3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array( 'keywordid' => 98, 'keyword' => 'sample keyword 34', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 99, 'keyword' => 'sample keyword 35', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 100, 'keyword' => 'sample keyword 36', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 97, 'keyword' => 'sample keyword 37', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 96, 'keyword' => 'sample keyword 38', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 95, 'keyword' => 'sample keyword 39', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 94, 'keyword' => 'sample keyword 40', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 93, 'keyword' => 'sample keyword 41', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 92, 'keyword' => 'sample keyword 42', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 91, 'keyword' => 'sample keyword 43', 'type' => 'NATURAL', 'longname' => 'UK' ) ); $order = array(100, 91, 95); $order = array_flip($order); $noMatchBucket = count($order); $temp = array_fill(0, $noMatchBucket + 1, array()); foreach ($data as $item) { $bucket = isset($order[$item['keywordid']]) ? $order[$item['keywordid']] : $noMatchBucket; $temp[$bucket][] = $item; } $data = array(); foreach ($temp as $bucket) { $data = array_merge($data, $bucket); } print_r($data);
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
Array ( [0] => Array ( [keywordid] => 100 [keyword] => sample keyword 36 [type] => NATURAL [longname] => UK ) [1] => Array ( [keywordid] => 91 [keyword] => sample keyword 43 [type] => NATURAL [longname] => UK ) [2] => Array ( [keywordid] => 95 [keyword] => sample keyword 39 [type] => NATURAL [longname] => UK ) [3] => Array ( [keywordid] => 98 [keyword] => sample keyword 34 [type] => NATURAL [longname] => UK ) [4] => Array ( [keywordid] => 99 [keyword] => sample keyword 35 [type] => NATURAL [longname] => UK ) [5] => Array ( [keywordid] => 97 [keyword] => sample keyword 37 [type] => NATURAL [longname] => UK ) [6] => Array ( [keywordid] => 96 [keyword] => sample keyword 38 [type] => NATURAL [longname] => UK ) [7] => Array ( [keywordid] => 94 [keyword] => sample keyword 40 [type] => NATURAL [longname] => UK ) [8] => Array ( [keywordid] => 93 [keyword] => sample keyword 41 [type] => NATURAL [longname] => UK ) [9] => Array ( [keywordid] => 92 [keyword] => sample keyword 42 [type] => NATURAL [longname] => UK ) )

preferences:
67.59 ms | 415 KiB | 5 Q