I have many arrays inside one array and I want to sort those arrays inside the array by two arguements. Those two arguments are on the hand true or false and on the other hand a unix timestamp. Here is an example:
array(3) => {
array(3) { ["Sticky"]=> bool(true) ["Timestamp"]=> int(1507696669) ["Title"]=> string(12) "TestArtikel2" }
array(3) { ["Sticky"]=> bool(false) ["Timestamp"]=> int(1507696645) ["Title"]=> string(12) "TestArtikel1" }
array(3) { ["Sticky"]=> bool(true) ["Timestamp"]=> int(1507688257) ["Title"]=> string(4) "Home" }
}
I want to get it sorted by the newest timestamp. But also, I want all arrays which contains true sorted before the false arrays. At the end it should look like this:
array(3) => {
array(3) { ["Sticky"]=> bool(true) ["Timestamp"]=> int(1507696669) ["Title"]=> string(12) "TestArtikel2" }
array(3) { ["Sticky"]=> bool(true) ["Timestamp"]=> int(1507688257) ["Title"]=> string(4) "Home" }
array(3) { ["Sticky"]=> bool(false) ["Timestamp"]=> int(1507696645) ["Title"]=> string(12) "TestArtikel1" }
}
My question now is, how can I do that? I have litteraly no idea, sorry..
This one doesn't work:
foreach ($arr as $key => $row) {
$bool[$key] = $row["Sticky"];
$time[$key] = $row["Timestamp"];
}
$allNews = array_multisort($bool, SORT_DESC, $time, SORT_DESC, $allNews);
foreach($allNews as $article){
var_dump($article);
echo "<br>";
}
Kind regards