Sorting a associative array based on two keys - php

I want to sort the id field by pushing array record with null value to bottom. If id value is present, then sort the col_1 by asc.
I have a multidimensional array like this.
Array
(
[0]=> Array
(
[id]=>1166
[col_1]=>9.4
)
[1]=> Array
(
[id]=>
[col_1]=>2.4
)
[2]=> Array
(
[id]=>1012
[col_1]=>0.96
)
[3]=> Array
(
[id]=>1856
[col_1]=>7.47
)
)
I want to sort it by id as well as col_1.
I tried
foreach ($arr as $key => $row) {
$x[$key] = $row['id'];
$y[$key] = $row['col_1'];
}
array_multisort($x, SORT_DESC, $y, SORT_ASC, $arr);
I got the following as my result
Array
(
[0]=> Array
(
[id]=>1856
[col_1]=>7.47
)
[1]=> Array
(
[id]=>1166
[col_1]=>9.4
)
[2]=> Array
(
[id]=>1012,
[col_1]=>0.96
)
[3]=> Array
(
[id]=>
[col_1]=>2.47
)
)
But I want the result as,
Array
(
[0]=> Array
(
[id]=>1012
[col_1]=>0.96
)
[1]=> Array
(
[id]=>1856
[col_1]=>7.47
)
[2]=> Array
(
[id]=>1166
[col_1]=>9.4
)
[3]=> Array
(
[id]=>
[col_1]=>2.4
)
)
'id' field can be null also for some records. But col_1 will be there for all the records.

Not exactly sophisticated, but readable and straight forward:
<?php
$data = [
[
'id' => 1166,
'col_1' => 9.4
],
[
'id' => null,
'col_1' => 2.4
],
[
'id' => 1012,
'col_1' => 0.96
],
[
'id' => 1856,
'col_1' => 7.47
]
];
usort($data, function($a, $b) {
return ($a['col_1']>$b['col_1']);
});
usort($data, function($a) {
return !isset($a['id']);
});
print_r($data);
The output obviously is:
Array
(
[0] => Array
(
[id] => 1012
[col_1] => 0.96
)
[1] => Array
(
[id] => 1856
[col_1] => 7.47
)
[2] => Array
(
[id] => 1166
[col_1] => 9.4
)
[3] => Array
(
[id] =>
[col_1] => 2.4
)
)
In your comment below you now make an additional requirement. I doubt there is a direct way to evaluate both requirements in a straight forward sorting approach. So why not try a readable and obvious one:
<?php
$data = [
[
'id' => 1166,
'col_1' => 9.4
],
[
'id' => null,
'col_1' => 2.4
],
[
'id' => null,
'col_1' => 0.2
],
[
'id' => 1012,
'col_1' => 0.96
],
[
'id' => null,
'col_1' => 12
],
[
'id' => 1856,
'col_1' => 7.47
]
];
usort($data, function($a, $b) {
return ($a['col_1']>$b['col_1']);
});
$withId = array_filter($data, function($entry) {
return isset($entry ['id']);
});
$withoutId = array_filter($data, function($entry) {
return !isset($entry ['id']);
});
$data = array_merge($withId, $withoutId);
print_r($data);
The output obviously is:
Array
(
[0] => Array
(
[id] => 1012
[col_1] => 0.96
)
[1] => Array
(
[id] => 1856
[col_1] => 7.47
)
[2] => Array
(
[id] => 1166
[col_1] => 9.4
)
[3] => Array
(
[id] =>
[col_1] => 0.2
)
[4] => Array
(
[id] =>
[col_1] => 2.4
)
[5] => Array
(
[id] =>
[col_1] => 12
)
)

you can use the usort function to make a custom sort.
function customSort($a, $b) {
if (null === $a['id'] && null === $b['id']) {
return 0;
}
if (null === $a['id']) {
return 1;
}
if (null === $b['id']) {
return -1;
}
return ($a['col_1'] < $b['col_1']) ? -1 : 1;
}
$array = [
[
'id' => 1012,
'col_1' => 0.96
],
[
'id' => 1856,
'col_1' => 7.47
],
[
'id' => null,
'col_1' => 2.4
],
[
'id' => 1166,
'col_1' => 9.4
],
];
usort($array, 'customSort');
print_r($array);
This returns
Array
(
[0] => Array
(
[id] => 1012
[col_1] => 0.96
)
[1] => Array
(
[id] => 1856
[col_1] => 7.47
)
[2] => Array
(
[id] => 1166
[col_1] => 9.4
)
[3] => Array
(
[id] =>
[col_1] => 2.4
)
)
Which is what you expected. Hope this helped.

Related

How to sort multidimensional array in PHP

I have tried almost all suggestions online, and I really can't figure out how to sort this SESSION array.
I want it sorted by "itemname"..
I have and want this output, but I need the itemname to determine which item array come first.
Array
(
[person] => Array
(
[namex] => Array
(
[itema] => Array
(
[itemid] => 43
[itemname] => def
)
[itemc] => Array
(
[itemid] => 33
[itemname] => abc
)
[itemg] => Array
(
[itemid] => 29
[itemname] => ghi
)
)
[namey] => Array
(
[itemj] => Array
(
[itemid] => 12
[itemname] => abc
)
[iteme] => Array
(
[itemid] => 44
[itemname] => jkl
)
[itemr] => Array
(
[itemid] => 20
[itemname] => rst
)
)
)
)
So, "person" stays the same, but name, item, itemid and itemname is always different.
Can anyone help me sort this by itemname?
I need the array to be like this, so can't change it up.
Also.. I need to access it later in a foreach, so I can print out the items.
As pointed out in the comments to the question the desired output is not really defined. You'd have to give a specific definition of the output, without that we have to assume what you probably are looking for:
<?php
$data = [
"person" => [
"namex" => [
"itema" => [
"itemid" => 43,
"itemname" => "def"
],
"itemc" => [
"itemid" => 33,
"itemname" => "abc"
],
"itemg" => [
"itemid" => 29,
"itemname" => "ghi"
]
],
"namey" => [
"itemj" => [
"itemid" => 12,
"itemname" => "abc"
],
"iteme" => [
"itemid" => 44,
"itemname" => "jkl"
],
"itemr" => [
"itemid" => 20,
"itemname" => "rst"
]
]
]
];
foreach ($data["person"] as $personName => &$person) {
uasort($person, function($a, $b) {
return $a["itemname"] > $b["itemname"];
});
}
print_r($data);
The obvious output is:
Array
(
[person] => Array
(
[namex] => Array
(
[itemc] => Array
(
[itemid] => 33
[itemname] => abc
)
[itema] => Array
(
[itemid] => 43
[itemname] => def
)
[itemg] => Array
(
[itemid] => 29
[itemname] => ghi
)
)
[namey] => Array
(
[itemj] => Array
(
[itemid] => 12
[itemname] => abc
)
[iteme] => Array
(
[itemid] => 44
[itemname] => jkl
)
[itemr] => Array
(
[itemid] => 20
[itemname] => rst
)
)
)
)
Assuming the input from the example is represented via array as:
<?php
$array = [
'person' => [
'namex' => [
'itema' => [
'itemid' => 43,
'itemname' => 'def'
],
'itemb' => [
'itemid' => 33,
'itemname' => 'abc'
],
'itemc' => [
'itemid' => 29,
'itemname' => 'ghi'
],
],
'namey' => [
'itema' => [
'itemid' => 12,
'itemname' => 'abc'
],
'itemb' => [
'itemid' => 44,
'itemname' => 'jkl'
],
'itemc' => [
'itemid' => 20,
'itemname' => 'rst'
],
],
]
];
You could do use array_multisort in a loop:
$ids = [];
foreach($array as $key => $value) {
foreach ($value as $newKey => $value2) {
$ids[$newKey] = array_column($value2, 'itemname');
array_multisort($ids[$newKey], SORT_NATURAL, $array[$key][$newKey]);
}
}
This will output
array(1) {
'person' =>
array(2) {
'namex' =>
array(3) {
'itemb' =>
array(2) {
'itemid' =>
int(33)
'itemname' =>
string(3) "abc"
}
'itema' =>
array(2) {
'itemid' =>
int(43)
'itemname' =>
string(3) "def"
}
'itemc' =>
array(2) {
'itemid' =>
int(29)
'itemname' =>
string(3) "ghi"
}
}
'namey' =>
array(3) {
'itema' =>
array(2) {
'itemid' =>
int(12)
'itemname' =>
string(3) "abc"
}
'itemb' =>
array(2) {
'itemid' =>
int(44)
'itemname' =>
string(3) "jkl"
}
'itemc' =>
array(2) {
'itemid' =>
int(20)
'itemname' =>
string(3) "rst"
}
}
}
}

finding matching and corresponding values in 2 arrays

I have 2 arrays:
first array of total transactions (haystack):
[0] => Array (
[transaction_id] => 62369600431
[invoice_number] => 37161
)
[1] => Array (
[transaction_id] => 62369595048
[invoice_number] => 37346
)
[2] => Array (
[transaction_id] => 62369537530
[invoice_number] => 38064
)
Second array of select orders (needle):
[0] => Array (
[invoice_number] => 37161
)
[1] => Array (
[invoice_number] => 37346
)
My goal is to create a third array that finds all transaction_id from the first array that have a match of order_id from the second.
I have tried array_merge and array_intersect both unsuccessfully (because I don't fully understand how to use them obviously.)
You might use array_filter and get all the invoice_numbers to check for using example array_column.
Then in the filter, check if the number occurs in the invoice_numbers using in_array.
$array1 = [
[
"transaction_id" => 62369600431,
"invoice_number" => 37161
],
[
"transaction_id" => 62369595048,
"invoice_number" => 37346
],
[
"transaction_id" => 62369600431,
"invoice_number" => 38064
]
];
$array2 = [
[
"invoice_number" => 37161
],
[
"invoice_number" => 37346
]
];
$invoiceNumbers = array_column($array2, "invoice_number");
$result = array_filter($array1, function($x) use ($invoiceNumbers) {
return in_array($x["invoice_number"], $invoiceNumbers);
});
print_r($result);
Output
Array
(
[0] => Array
(
[transaction_id] => 62369600431
[invoice_number] => 37161
)
[1] => Array
(
[transaction_id] => 62369595048
[invoice_number] => 37346
)
)
Php demo

Merge first array particular key and value into second array

I have 2 array
$arr1 = Array (
[0] => Array ( [customer_id] => 1 [Expire] => 2019-05-14 [paid] => 1 )
[1] => Array ( [customer_id] => 2 [Expire] => 2019-06-20 [paid] => 0 ))
and
$arr2 = Array (
[0] => Array ( [id] => 3943 [customer_id] => 1 [Expire] => 2019-05-14 )
[1] => Array ( [id] => 3944 [customer_id] => 1[Expire] => 2019-05-14 )
[2] => Array ( [id] => 4713 [customer_id] => 2 [Expire] => 2019-06-20 )
)
and try to put first array key and value [paid]=>1 or 0 in second array if customer id and expire match like
Array (
[0] => Array ( [id] => 3943 [customer_id] => 1 [Expire] => 2019-05-14 [paid] => 1)
[1] => Array ( [id] => 3944 [customer_id] => 1 [Expire] => 2019-05-14 [paid] => 1)
[2] => Array ( [id] => 4713 [customer_id] => 2 [Expire] => 2019-06-20 [paid] => 0)
)
I try to merge array in php but not get exact what i want. Is there any php function to do it?.
Loop your second array $arr2, and find the index of the first array $arr1 where the column customer_id is the same as in the current iteration of $arr2. array_search() returns that index, which we can then use to fetch the paid index of that array. Then we append it to our array $arr2, by doing $a['paid'] = $paid;.
Since we loop the array by reference (the & before $a in the loop), the changes we make to it, will be applied back to the original array.
foreach ($arr2 as &$a) {
$customerID = $a['customer_id']; // This customer ID
$arr1_key = array_search($customerID, array_column($arr1, 'customer_id')); // Find the index of this customerID in the first array
$paid = $arr1[$arr1_key]['paid']; // Find the paid value matching that customer ID
$a['paid'] = $paid;
}
Live demo at https://3v4l.org/Meqtu
Update
If you need it to match the ID as well as the expiration date, then use array_filter() to fetch the array-element within $arr1 that matches the date and the ID. Using reset(), we use the first element in that array.
foreach ($arr2 as &$a) {
// Find the sub-array of $arr1 that matches this array's date and ID
$arr1_match = array_filter($arr1, function($v) use ($a) {
return $v['customer_id'] == $a['customer_id'] && $v['Expire'] == $a['Expire'];
});
// Get the first element from the result
$paid = reset($arr1_match)['paid'];
// Append the paid-value to this array (done by reference)
$a['paid'] = $paid;
}
Live demo at https://3v4l.org/mov6d
sometimes things can be done in hard way:)
<?php
$arr1 = [
['customer_id' => 1, 'Expire' => '2019-05-14', 'paid' => 1],
['customer_id' => 2, 'Expire' => '2019-06-20', 'paid' => 0],
];
$arr2 = [
['id' => 3943, 'customer_id' => 1, 'Expire' => '2019-05-14'],
['id' => 3944, 'customer_id' => 1, 'Expire' => '2019-05-14'],
['id' => 3945, 'customer_id' => 2, 'Expire' => '2019-05-14'],
['id' => 4713, 'customer_id' => 2, 'Expire' => '2019-06-20'],
];
foreach ($arr2 as &$item2) {
foreach ($arr1 as $item1) {
if (
$item2['customer_id'] === $item1['customer_id']
&& $item2['Expire'] === $item1['Expire']
) {
$item2['paid'] = $item1['paid'];
break;
}
}
}
unset($item2);
var_dump($arr2);
If you cannot change the layout of the first array I think it will be best to first create an intermediate array that keeps a record of all expire dates for every customer.
The following implementation does not require you to use a nested loop.
<?php
$arr1 = [
['customer_id' => 1, 'Expire' => '2019-05-14', 'paid' => 1],
['customer_id' => 2, 'Expire' => '2019-06-20', 'paid' => 0],
];
$arr2 = [
['id' => 3943, 'customer_id' => 1, 'Expire' => '2019-05-14'],
['id' => 3944, 'customer_id' => 1, 'Expire' => '2019-05-14'],
['id' => 3945, 'customer_id' => 2, 'Expire' => '2019-05-14'],
['id' => 4713, 'customer_id' => 2, 'Expire' => '2019-06-20'],
];
// Create a list of all paid, expiry dates, keyed by customer_id
$payed = [];
foreach ($arr1 as $item) {
if (!isset($payed[$item['customer_id']])) {
$payed[$item['customer_id']] = [];
}
$payed[$item['customer_id']][] = $item['Expire'];
}
// Lookup the customer and expire date for every entry
$arr2 = array_map(function($item) use ($payed) {
$item['paid'] = in_array($item['Expire'], $payed[$item['customer_id']] ?? []);
return $item;
}, $arr2);
Result:
Array
(
[0] => Array
(
[id] => 3943
[customer_id] => 1
[Expire] => 2019-05-14
[paid] => 1
)
[1] => Array
(
[id] => 3944
[customer_id] => 1
[Expire] => 2019-05-14
[paid] => 1
)
[2] => Array
(
[id] => 3945
[customer_id] => 2
[Expire] => 2019-05-14
[paid] =>
)
[3] => Array
(
[id] => 4713
[customer_id] => 2
[Expire] => 2019-06-20
[paid] => 1
)
)
See demo
This can fix the issue :
$arr1 = array(
["customer_id"=>1,"Expire"=> "2019-05-14", "paid"=>1],
["customer_id"=>2,"Expire"=> "2019-06-20", "paid"=>0]
);
$arr2 = array(
["id"=>3943, "customer_id"=>1,"Expire"=> "2019-05-14"],
["id"=>3944,"customer_id"=>2,"Expire"=> "2019-06-20"],
["id"=>4713,"customer_id"=>1,"Expire"=> "2019-05-14"]
);
$result= array();
function getRowByCustomerID($id, $array){
foreach($array as $value){
if($value['customer_id'] ==$id){
return $value;
}
}
return null;
}
foreach($arr2 as $subarr){
$object = getRowByCustomerID($subarr['customer_id'],$arr1 );
if(!is_null($object)){
$object['id']=$subarr['id'];
$result[]= $object;
}
}
var_dump($result);
the output is similar to what you are looking for :
array(3) {
[0]=>
array(4) {
["customer_id"]=>
int(1)
["Expire"]=>
string(10) "2019-05-14"
["paid"]=>
int(1)
["id"]=>
int(3943)
}
[1]=>
array(4) {
["customer_id"]=>
int(2)
["Expire"]=>
string(10) "2019-06-20"
["paid"]=>
int(0)
["id"]=>
int(3944)
}
[2]=>
array(4) {
["customer_id"]=>
int(1)
["Expire"]=>
string(10) "2019-05-14"
["paid"]=>
int(1)
["id"]=>
int(4713)
}
}

In php is there a function like array_column for multidimensional arrays [duplicate]

This question already has answers here:
How to group subarrays by a column value?
(20 answers)
Closed 2 years ago.
Is there function that works similar to array_column for multidimensional arrays? Is there a function that translates the first array below to the second:
Array
(
[0] => Array
(
[foodType] => fruits
[itemID] => 1
[itemName] => apple
)
[1] => Array
(
[foodType] => fruits
[itemID] => 2
[itemName] => banana
)
[2] => Array
(
[foodType] => veggies
[itemID] => 3
[itemName] => carrot
)
[3] => Array
(
[foodType] => veggies
[itemID] => 4
[itemName] => broccoli
)
)
Resulting array:
Array
(
[fruits] => Array
(
[0] => Array
(
[itemID] => 1
[itemName] => apple
)
[1] => Array
(
[itemID] => 2
[itemName] => banana
)
)
[veggies] => Array
(
[0] => Array
(
[itemID] => 3
[itemName] => carrot
)
[1] => Array
(
[itemID] => 4
[itemName] => broccoli
)
)
)
No, there is not a function to get your expected output natively, though you can make your own functions, just use array_column to get the types/column, and then loop over your array, on match remove the item as to not duplicate iterations.
Something like:
<?php
$data = [
['foodType' => 'fruits', 'itemID' => 1, 'itemName' => 'apple'],
['foodType' => 'fruits', 'itemID' => 2, 'itemName' => 'banana'],
['foodType' => 'veggies', 'itemID' => 3, 'itemName' => 'carrot'],
['foodType' => 'veggies', 'itemID' => 4, 'itemName' => 'broccoli']
];
function array_column_multi ($array, $column) {
$types = array_unique(array_column($array, $column));
$return = [];
foreach ($types as $type) {
foreach ($array as $key => $value) {
if ($type === $value[$column]) {
unset($value[$column]);
$return[$type][] = $value;
unset($array[$key]);
}
}
}
return $return;
}
print_r(array_column_multi($data, 'foodType'));
https://3v4l.org/KQVeN
Result:
Array
(
[fruits] => Array
(
[0] => Array
(
[itemID] => 1
[itemName] => apple
)
[1] => Array
(
[itemID] => 2
[itemName] => banana
)
)
[veggies] => Array
(
[0] => Array
(
[itemID] => 3
[itemName] => carrot
)
[1] => Array
(
[itemID] => 4
[itemName] => broccoli
)
)
)
Oh I just noticed that you're aggregating them by ID. There's not a function for that, you're going to need to iterate over the input with a loop, and populate an output array with the data you want. Eg:
$output = [];
foreach($input_array as $item) {
$output[$item['id']][] = [
'itemID' => $item['itemID'],
'itemName' => $item['itemName']
];
}
Quite old question, but I hope it help someone. Unfortunately there's no native function yet but output is achievable using php's array_filter():
$foods = [
[
'foodType' => 'fruits',
'itemID' => 1,
'itemName' => 'apple',
],
[
'foodType' => 'fruits',
'itemID' => 2,
'itemName' => 'banana',
],
[
'foodType' => 'veggies',
'itemID' => 3,
'itemName' => 'carrot',
],
[
'foodType' => 'veggies',
'itemID' => 4,
'itemName' => 'broccoli',
]
];
$grouped_foods = [];
$groupByColumn = 'foodType';
array_filter($foods, function ($foodItem) use(&$grouped_foods, $groupByColumn) {
$grouped_foods[$foodItem[$groupByColumn]][] = array_filter($foodItem, function ($key) use($groupByColumn) {
return $key != $groupByColumn;
}, ARRAY_FILTER_USE_KEY);
});
echo "<pre>";
print_R($grouped_foods);
echo "</pre>";
see in action: https://3v4l.org/bbX5A
Disclaimer: for/foreach loops are significantly faster in performance than native array functions.
I prefer using the following solution.
Example
"allergens" => array:5 [
0 => array:2 [
"id" => "10"
"object" => array:1 [
"allergens" => "10"
]
]
1 => array:2 [
"id" => "11"
"object" => array:1 [
"allergens" => "11"
]
]
2 => array:2 [
"id" => "4"
"object" => array:1 [
"allergens" => "4"
]
]
]
Giving this example, if you would like an array containing only the value of allergens then use the following code.
Solution
$allergens = array_map( function ( $ar ) {
return $ar['allergens'];
}, array_column( $allergensArr, 'object' ) );
Result
array:5 [
0 => "10"
1 => "11"
2 => "4"
]

Sorting multidimensional array by two user defined values

I need to sort a multidimensional array by two values.
For example in the array will be 4 keys.
Array(
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => downloading
[2] => Title
[3] => 60
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => downloading
[2] => Title
[3] => 30
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => paused
[2] => Title
[3] => 30
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => completed
[2] => Title
[3] => 100
)
)
Is there a way I can sort the array so that it would sort the arrays with key completed first, then downloading second, then paused third and then also sort the arrays containing downloading and paused from 100 down to 0 by the 3 key?
Desired output would be
Array(
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => completed
[2] => Title
[3] => 100
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => downloading
[2] => Title
[3] => 60
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => downloading
[2] => Title
[3] => 30
)
Array
(
[0] => 4B642D022980E5EBAA7CF4B6E1CC93769921CB42
[1] => paused
[2] => Title
[3] => 30
)
)
uksort is what you need.
It is a sort that lets you define you own callback function.
This callback function is then used by uksort to reorder the array.
You need to write a function that will sort an array based on two criterias.
The first one is the alphabetical order of the field at indice 1 of your array (which contains the words completed, downloading, ...) and in case of tie you would then use the field at indice 3 of your array and sort in decreasing order.
Finally, you will need to pass the function you created as a parameter to uksort.
Hope it helps ! :)
You need to reformat your array and use array_multisort. It will also make thinks more readable:
<?php $ar = Array(
Array(
"id" => "4B642D022980E5EBAA7CF4B6E1CC93769921CB42",
"status" => "completed",
"title" => "Title",
"rank" => "100",
),
Array
(
"id" => "4B642D022980E5EBAA7CF4B6E1CC93769921CB42",
"status" => "downloading",
"title" => "Title",
"rank" => "60",
),
Array
(
"id" => "4B642D022980E5EBAA7CF4B6E1CC93769921CB42",
"status" => "downloading",
"title" => "Title",
"rank" => "30",
),
Array
(
"id" => "4B642D022980E5EBAA7CF4B6E1CC93769921CB42",
"status" => "paused",
"title" => "Title",
"rank" => "30",
),
);
var_dump($ar);
foreach ($ar as $key => $row) {
$status[$key] = $row['status'];
$rank[$key] = $row['rank'];
}
array_multisort($status, SORT_ASC, $rank, SORT_DESC, $ar);
var_dump($ar);
$array = [
[
'4B642D022980E5EBAA7CF4B6E1CC93769921CB42',
'downloading',
'Title',
'60',
],
[
'4B642D022980E5EBAA7CF4B6E1CC93769921CB42',
'downloading',
'Title',
'30',
],
[
'4B642D022980E5EBAA7CF4B6E1CC93769921CB42',
'paused',
'Title',
'30',
],
[
'4B642D022980E5EBAA7CF4B6E1CC93769921CB42',
'completed',
'Title',
'100',
]
];
usort($array, function($a, $b) {
if ($a[1] == $b[1]) {
if ($a[3] == $b[3]) {
return 0;
}
return ($a[3] > $b[3]) ? -1 : 1;
}
$status = ['completed', 'downloading', 'paused'];
foreach ($status as $st) {
if ($a[1] == $st)
return -1;
if ($b[1] == $st)
return 1;
}
return 0;
});
var_dump($array);

Categories