3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multi_dim = array( array('id' => 1, 'title' => 'Tv', 'cat' => 1, 'value' => 100), array('id' => 2, 'title' => 'Laptop', 'cat' => 1, 'value' => 200), array('id' => 3, 'title' => 'Phone', 'cat' => 1, 'value' => 100), array('id' => 4, 'title' => 'Painting', 'cat' => 2, 'value' => 100), ); $call_back = function( $a ){ if ( $a['cat'] == 1 && $a['value'] == 100 ){ return $a; } }; $callback = function ($a,$b) { if ( $a['cat'] >= $b['cat'] && $a['value'] >= $b['value'] ){ return true; } }; usort( $multi_dim,$callback ); $max = 1; $rand = mt_rand( 0, $max ); $slice = array_slice($multi_dim,0,2); var_dump($slice);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
array(2) { [0]=> array(4) { ["id"]=> int(3) ["title"]=> string(5) "Phone" ["cat"]=> int(1) ["value"]=> int(100) } [1]=> array(4) { ["id"]=> int(1) ["title"]=> string(2) "Tv" ["cat"]=> int(1) ["value"]=> int(100) } }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
array(2) { [0]=> array(4) { ["id"]=> int(1) ["title"]=> string(2) "Tv" ["cat"]=> int(1) ["value"]=> int(100) } [1]=> array(4) { ["id"]=> int(3) ["title"]=> string(5) "Phone" ["cat"]=> int(1) ["value"]=> int(100) } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/7EFMY on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/7EFMY on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/7EFMY on line 8
Process exited with code 255.

preferences:
147.33 ms | 401 KiB | 206 Q