Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php sort array by specific key


usort($array, function ($a, $b) {
  return ($a['specific_key'] < $b['specific_key']) ? -1 : 1;
});
Comment

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
Comment

php sort associative array by specific value

$price = array_column($inventory, 'price');

array_multisort($price, SORT_DESC, $inventory);
Comment

php sort by associative array value

//php 7+
usort($inventory, function ($item1, $item2) {
    return $item1['price'] <=> $item2['price'];
});
Comment

PREVIOUS NEXT
Code Example
Php :: first name of string php 
Php :: run shell script from php file 
Php :: get country from clouflare 
Php :: php string parse with separator explode 
Php :: laravel get auth user id 
Php :: laravel access JsonResponse content 
Php :: wordpress register post type 
Php :: from user id to user role wordpress 
Php :: search post by post title in wordpres 
Php :: unset session key 
Php :: Exception #0 (MagentoFrameworkExceptionValidatorException): Invalid template file: 
Php :: delete in crud php 
Php :: yii2 set cookie 
Php :: php if $_post 
Php :: cambiar entre versiones de php linux 
Php :: change minutes in to hours carbon 
Php :: create listener using laravel 
Php :: do while php 
Php :: check if string starts with php 
Php :: validation error laravel 8 with custom massage 
Php :: multiple search filter in laravel 
Php :: or where laravel 
Php :: how to add sidebar to page.php 
Php :: PDOException::("could not find driver") windows 
Php :: laravel validation regex 
Php :: wp tax_query in 
Php :: get user role in symfony 
Php :: how to create an associative array in php 
Php :: yii2 gridview filter exact value 
Php :: php generating number 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =