Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

associative array sorting by value in php

//php 
$a=array(array("id" => 4,"name"=> "Dog"),array("id" => 1,"name"=> "Cat"),array("id" => 3,"name"=> "Hourse"),array("id" => 2,"name"=> "Bear"),array("id" => 5,"name"=> "Zebra"));
$b = array_column($a,'name'); // which column needed to be sorted
array_multisort($b,SORT_ASC,$a); // sorts the array $a with respective of aray $b
 
PREVIOUS NEXT
Tagged: #associative #array #sorting #php
ADD COMMENT
Topic
Name
1+4 =