Skip to content

Instantly share code, notes, and snippets.

@hemraj7171
Created April 13, 2017 11:15
Show Gist options
  • Save hemraj7171/e2ec6ee8560282f7562e7e5489f32cb9 to your computer and use it in GitHub Desktop.
Save hemraj7171/e2ec6ee8560282f7562e7e5489f32cb9 to your computer and use it in GitHub Desktop.
Short Array with Custom Key Value in PHP
$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