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' ) ); echo '<h1>Unordered Array</h1><pre>'; print_r($data); echo '</pre>'; $order = array(-1, 100, 91, 95); echo '<h1>Order Array</h1><pre>'; print_r($order); echo '</pre>'; usort($data, function($a, $b) use($order) { $k1 = array_search($a['keywordid'], $order); $k2 = array_search($b['keywordid'], $order); if ($k1 == $k2) { return 0; } return ($k1 > $k2) ? -1 : 1; }); echo '<h1>Ordered Array</h1><pre>'; print_r($data); echo '</pre>'; ?>
Output for 7.0.0 - 7.1.0
<h1>Unordered Array</h1><pre>Array ( [0] => Array ( [keywordid] => 98 [keyword] => sample keyword 34 [type] => NATURAL [longname] => UK ) [1] => Array ( [keywordid] => 99 [keyword] => sample keyword 35 [type] => NATURAL [longname] => UK ) [2] => Array ( [keywordid] => 100 [keyword] => sample keyword 36 [type] => NATURAL [longname] => UK ) [3] => Array ( [keywordid] => 97 [keyword] => sample keyword 37 [type] => NATURAL [longname] => UK ) [4] => Array ( [keywordid] => 96 [keyword] => sample keyword 38 [type] => NATURAL [longname] => UK ) [5] => Array ( [keywordid] => 95 [keyword] => sample keyword 39 [type] => NATURAL [longname] => UK ) [6] => Array ( [keywordid] => 94 [keyword] => sample keyword 40 [type] => NATURAL [longname] => UK ) [7] => Array ( [keywordid] => 93 [keyword] => sample keyword 41 [type] => NATURAL [longname] => UK ) [8] => Array ( [keywordid] => 92 [keyword] => sample keyword 42 [type] => NATURAL [longname] => UK ) [9] => Array ( [keywordid] => 91 [keyword] => sample keyword 43 [type] => NATURAL [longname] => UK ) ) </pre><h1>Order Array</h1><pre>Array ( [0] => -1 [1] => 100 [2] => 91 [3] => 95 ) </pre><h1>Ordered Array</h1><pre>Array ( [0] => Array ( [keywordid] => 95 [keyword] => sample keyword 39 [type] => NATURAL [longname] => UK ) [1] => Array ( [keywordid] => 91 [keyword] => sample keyword 43 [type] => NATURAL [longname] => UK ) [2] => Array ( [keywordid] => 100 [keyword] => sample keyword 36 [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 ) ) </pre>
Output for 5.3.0 - 5.6.28
<h1>Unordered Array</h1><pre>Array ( [0] => Array ( [keywordid] => 98 [keyword] => sample keyword 34 [type] => NATURAL [longname] => UK ) [1] => Array ( [keywordid] => 99 [keyword] => sample keyword 35 [type] => NATURAL [longname] => UK ) [2] => Array ( [keywordid] => 100 [keyword] => sample keyword 36 [type] => NATURAL [longname] => UK ) [3] => Array ( [keywordid] => 97 [keyword] => sample keyword 37 [type] => NATURAL [longname] => UK ) [4] => Array ( [keywordid] => 96 [keyword] => sample keyword 38 [type] => NATURAL [longname] => UK ) [5] => Array ( [keywordid] => 95 [keyword] => sample keyword 39 [type] => NATURAL [longname] => UK ) [6] => Array ( [keywordid] => 94 [keyword] => sample keyword 40 [type] => NATURAL [longname] => UK ) [7] => Array ( [keywordid] => 93 [keyword] => sample keyword 41 [type] => NATURAL [longname] => UK ) [8] => Array ( [keywordid] => 92 [keyword] => sample keyword 42 [type] => NATURAL [longname] => UK ) [9] => Array ( [keywordid] => 91 [keyword] => sample keyword 43 [type] => NATURAL [longname] => UK ) ) </pre><h1>Order Array</h1><pre>Array ( [0] => -1 [1] => 100 [2] => 91 [3] => 95 ) </pre><h1>Ordered Array</h1><pre>Array ( [0] => Array ( [keywordid] => 95 [keyword] => sample keyword 39 [type] => NATURAL [longname] => UK ) [1] => Array ( [keywordid] => 91 [keyword] => sample keyword 43 [type] => NATURAL [longname] => UK ) [2] => Array ( [keywordid] => 100 [keyword] => sample keyword 36 [type] => NATURAL [longname] => UK ) [3] => Array ( [keywordid] => 94 [keyword] => sample keyword 40 [type] => NATURAL [longname] => UK ) [4] => Array ( [keywordid] => 93 [keyword] => sample keyword 41 [type] => NATURAL [longname] => UK ) [5] => Array ( [keywordid] => 92 [keyword] => sample keyword 42 [type] => NATURAL [longname] => UK ) [6] => Array ( [keywordid] => 96 [keyword] => sample keyword 38 [type] => NATURAL [longname] => UK ) [7] => Array ( [keywordid] => 99 [keyword] => sample keyword 35 [type] => NATURAL [longname] => UK ) [8] => Array ( [keywordid] => 97 [keyword] => sample keyword 37 [type] => NATURAL [longname] => UK ) [9] => Array ( [keywordid] => 98 [keyword] => sample keyword 34 [type] => NATURAL [longname] => UK ) ) </pre>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/RuTrT on line 78
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/RuTrT on line 78
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/RuTrT on line 78
Process exited with code 255.