3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(array("id" => 1,"title" => "Hello World", "body" => "Hi Jude All this is my content"), array("id" => 2,"title" => "Hello World Boy", "body" => "Hi All this is my content Girl"), array("id" => 3,"title" => "Hello Kids", "body" => "Hi All this is my content Kid"), array("id" => 4,"title" => "Hello World Jude", "body" => "Hi All this is my content Jude"), array("id" => 5,"title" => "Hello World Jude January", "body" => "Hi All this is my content Jan"), array("id" => 6,"title" => "Hello World January June Lord", "body" => "Hi All this is my content Jan Jude Lord")); $str = "Hello world January jude"; function sort_most_needles(&$array, $str) { $needles = explode(" ", $str); usort($array, fn($a, $b) => array_uintersect($needles, explode(" ", $b['title']), 'strcasecmp') <=> array_uintersect($needles, explode(" ", $a['title']), 'strcasecmp') ); } sort_most_needles($arr, $str); var_export($arr);
Output for 7.4.4 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( 0 => array ( 'id' => 5, 'title' => 'Hello World Jude January', 'body' => 'Hi All this is my content Jan', ), 1 => array ( 'id' => 6, 'title' => 'Hello World January June Lord', 'body' => 'Hi All this is my content Jan Jude Lord', ), 2 => array ( 'id' => 4, 'title' => 'Hello World Jude', 'body' => 'Hi All this is my content Jude', ), 3 => array ( 'id' => 1, 'title' => 'Hello World', 'body' => 'Hi Jude All this is my content', ), 4 => array ( 'id' => 2, 'title' => 'Hello World Boy', 'body' => 'Hi All this is my content Girl', ), 5 => array ( 'id' => 3, 'title' => 'Hello Kids', 'body' => 'Hi All this is my content Kid', ), )
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/uJuni on line 13
Process exited with code 255.
Output for 7.1.25 - 7.1.31, 7.2.0 - 7.2.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/uJuni on line 13
Process exited with code 255.

preferences:
116.49 ms | 409 KiB | 5 Q