What is the best way to sort an array by maintaining it’s key associations as well?
$array = array(‘a’=>’foo’,'b’=>’bar’,'c’=>’baz’);
asort($array);
print_r($array);
Array
(
[b] => bar
=> baz
[a] => foo
)
What is the best way to sort an array by maintaining it’s key associations as well?
$array = array(‘a’=>’foo’,'b’=>’bar’,'c’=>’baz’);
asort($array);
print_r($array);
Array
(
[b] => bar
=> baz
[a] => foo
)
What will be the out put of the following code snippet ?
<?php
function setcase(&$value, &$key){
$value = strtoupper($value);
}
$type = array('internal','external');
$format[] = array('rss','html','xml');
$format[] = array('csv','jason');
$map = array_combine($type, $format);
array_walk_recursive($map, 'setcase');
print_r($map);
?>
Only scalar values will be converted to upper cases. ‘ internal’ and ‘external’ are not passed into the user defined function.
Array
(
[internal] => Array
(
[0] => RSS
[1] => HTML
[2] => XML
)
[external] => Array
(
[0] => CSV
[1] => JASON
)
)