Reorder the elements in an array using php -


i have following array , changeable time time.

array (     [for sale] => sale     [sold] => sold     [to let] => let     [let] => let     [under offer] => under offer     [exchanged] => exchanged     [withdrawn] => withdrawn     [acquired] => acquired ) 

no matter what's initial sequence when page loads should

array     (         [for sale] => sale                [under offer] => under offer         [exchanged] => exchanged         [withdrawn] => withdrawn         [acquired] => acquired         [sold] => sold         [to let] => let         [let] => let     ) 

basically these 3 elements should stay @ bottom of array.

[sold] => sold [to let] => let [let] => let 

any highly appreciated. in advance.

here i've used in_array() match key given keys 'sold','to let','let', unset key $input array , push key value array.

<?php $input = array(     'for sale' => 'for sale',     'sold' => 'sold',     'to let' => ' let',     'let' => 'let',     'under offe' => 'under offer',     'exchanged' => 'exchanged',     'withdrawn' => 'withdrawn',     'acquired' => 'acquired' );  foreach ($input $key => $val) {     if (in_array($key, array('sold', 'to let', 'let'))) {         unset($input[$key]);         $input[$key] = $val;     } }  echo "<pre>"; print_r($input); ?> 

this output :

array (     [for sale] => sale     [under offe] => under offer     [exchanged] => exchanged     [withdrawn] => withdrawn     [acquired] => acquired     [sold] => sold     [to let] =>  let     [let] => let ) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -