Sort the elements of a two-dimensional array in the given order.

You can use usort for sorting

$hot = [145.147.146.148.144.143];

$arr= [['id'= >146.'name'= >'146'],
    ['id'= >143.'name'= >'143'],
    ['id'= >144.'name'= >'144'],
    ['id'= >145.'name'= >'145'],
    ['id'= >147.'name'= >'147'],
    ['id'= >148.'name'= >'148']]; usort($arr.function ($a.$b) use ($hot) {
    return array_search($a['id'].$hot) < array_search($b['id'].$hot)? -1 : 1;
});


var_dump($arr);


array(6) {[0] = >array(2) {["id"] = >int(145)
    ["name"] = >string(3) "145"
  }
  [1] = >array(2) {["id"] = >int(147)
    ["name"] = >string(3) "147"
  }
  [2] = >array(2) {["id"] = >int(146)
    ["name"] = >string(3) "146"
  }
  [3] = >array(2) {["id"] = >int(148)
    ["name"] = >string(3) "148"
  }
  [4] = >array(2) {["id"] = >int(144)
    ["name"] = >string(3) "144"
  }
  [5] = >array(2) {["id"] = >int(143)
    ["name"] = >string(3) "143"}}Copy the code