Sorting the array with Custom Key in PHP -


i have array of 1 structure below

$array1 = array( [123] => array('1'=>'1','2'=>'3'), [345] => array('1'=>'3','2'=>'5'), [789] => array('1'=>'1','2'=>'5'), [567] => array('1'=>'6','2'=>'5'), ); 

and array structure $array2 = array(567,345,789,123);

now want sort 1 php sort function, mean sort first array second 1 looks desired output below

$array1 = array( [567] => array('1'=>'6','2'=>'5'), [345] => array('1'=>'3','2'=>'5'), [789] => array('1'=>'1','2'=>'5'), [123] => array('1'=>'1','2'=>'3'), ); 

i want these desired result sorting function exists.

thanks.

loop $array2 , populate third array follows:

$array1 = array(     [123] => array('1'=>'1','2'=>'3'),     [345] => array('1'=>'3','2'=>'5'),     [789] => array('1'=>'1','2'=>'5'),     [567] => array('1'=>'6','2'=>'5'), );  $array2 = array(567,345,789,123);  $orderedarray = array(); foreach ($array2 $key) {     $orderedarray[$key] = $array1[$key]; } 

and if want function:

function orderarray($arraytoorder, $keys) {     $ordered = array();     foreach ($keys $key) {         $ordered[$key] = $arraytoorder[$key];     }     return $ordered; }  $myorderedarray = orderarray($array1, $array2); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -