Created
April 13, 2017 11:15
-
-
Save hemraj7171/e2ec6ee8560282f7562e7e5489f32cb9 to your computer and use it in GitHub Desktop.
Short Array with Custom Key Value in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array1 = Array | |
( | |
'hemraj' => Array | |
( | |
'name' => 'hemraj', | |
'age' => '26', | |
), | |
'bishnu' => Array | |
( | |
'name' => 'bishnu', | |
'age' => '31', | |
), | |
'manish' => Array | |
( | |
'name' => 'manish', | |
'age' => '28', | |
) | |
); | |
echo "this is the original version of array"; | |
print_r($array1); | |
echo "========================"; | |
$array2 = array('manish', 'hemraj','bishnu'); | |
uksort($array1, function($a, $b)use($array2) { | |
foreach($array2 as $value){ | |
if($a == $value){ | |
return 0; | |
break; | |
} | |
if($b == $value){ | |
return 1; | |
break; | |
} | |
} | |
}); | |
echo "<pre>"; | |
//this is the modified version of array | |
print_r($array1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment