3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 - 7.1.0
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 ) )