php - need soting multi dimensional array based on another array displaying order -
i need sorting array based array sort value.
actual array : array(name=>'jk',age=>'20',place=>'india',year=>array(marks1=>array(sub1=>50,sub3=>70,sub7=>65,sub5=>75,sub4=>35), marks2=>array(sub8=>50,sub10=>70,sub12=>75,sub9=>35,sub11=>65))
sorting order array : array(name=>1,year=>2,age=>3,place=>4,sub1=>5,sub3=>6,sub4=>7,sub5=>8,sub7=>9,sub8=>10,sub9=>11,sub10=>12,sub11=>13,sub12=>14)
expected result array:
array( name=>'jk', year=>array( marks1=>array( sub1=>50, sub3=>70, sub4=>35, sub5=>75 sub7=>65 ), marks2=>array( sub8=>50, sub9=>35, sub10=>70, sub11=>65, sub12=>75 ), age=>'20', place=>'india' )
i hope :)
$array1 = array(name=>'jk',age=>'20',place=>'india',year=>array(marks1=>array(sub1=>50,sub3=>70,sub7=>65,sub5=>75,sub4=>35), marks2=>array(sub8=>50,sub10=>70,sub12=>75,sub9=>35,sub11=>65)); $array2 = array(name=>1,year=>2,age=>3,place=>4,sub1=>5,sub3=>6,sub4=>7,sub5=>8,sub7=>9,sub8=>10,sub9=>11,sub10=>12,sub11=>13,sub12=>14); //final array $final_array = array(); //for each value in sorting array foreach ($array2 $key => $value) { //store result in final array $final_array[$value] = $array1[$key]; } //display array check result var_dump($final_array);
Comments
Post a Comment