I have a array both key
& value
are string
like
$myArr = array(
'ball'=>'zebra',
'tree'=>'plant',
'zoo'=>'animal' );
I need to sort array
by its values
and keep key
, value
association, so output would be like
$sortedArr = array(
'zoo'=>'animal',
'tree'=>'plant',
'ball'=>'zebra' );
I am looking for shortest and smartest solution to achieve this, if you have that one please share with me.
Take a look at asort:
$myArr = array('ball'=>'zebra', 'tree'=>'plant', 'zoo'=>'animal');
asort($myArr);
echo print_r($myArr, TRUE);
Result:
Array
(
[zoo] => animal
[tree] => plant
[ball] => zebra
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments