Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel short collection by keys based on array

$collection = collect([
    ['name' => 'A', 'status' => 0],
    ['name' => 'B', 'status' => 3],
    ['name' => 'C', 'status' => 0],
    ['name' => 'D', 'status' => 1],
    ['name' => 'E', 'status' => 2],
    ['name' => 'F', 'status' => 1],
    ['name' => 'G', 'status' => 3],
    ['name' => 'H', 'status' => 1],
    ['name' => 'I', 'status' => 2],
    ['name' => 'J', 'status' => 3],
]);

// define status priority here
$statusPriorities = [2, 1, 3, 0];

$collection->sortBy(function($order) use($statusPriorities){
   return array_search($order['status'], $statusPriorities);
})->values()->all();
Comment

PREVIOUS NEXT
Code Example
Php :: add code in header 
Php :: php tree function parrent_id 
Php :: Store authentication status in a cookies 
Php :: symfony create form multiple entities 
Php :: php convert html code to text 
Php :: laravel model where set fields laravel 
Php :: saleor meaning 
Php :: Laravel route returning error 404 when attempt is made to pass value to controller function 
Php :: wordpress not logging when using ngrok 
Php :: laravel-filemanager 404 error 
Php :: php getgmail name 
Php :: 0.02 eth to php 
Php :: laravel create multiple rows 
Php :: php tipi array 
Php :: php array push key value 
Php :: php get result sql server 
Php :: ? in php 
Php :: wordpress change permalink on upload 
Php :: how to unhash password_hash in php 
Php :: how to do taxonomy filter in wordpress 
Php :: how to save array of inputs in php 
Php :: addphp calculate next letter 
Java :: when is the first day of spring 
Java :: spigot get player from uuid 
Java :: isprime check formula java 
Java :: spring application properties mysql jpa 
Java :: java check if able to parse int 
Java :: java cwd 
Java :: gravatar default 
Java :: maven source option 5 is no longer supported use 7 or later 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =