3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new \StdClass; $obj->textfield->id = 'text12'; $obj->textfield->text = 'herro'; $anotherObj = new \StdClass; $anotherObj->textfield->id = 'text1'; $anotherObj->textfield->text = 'moarrr text'; $yesAnother = new \StdClass; $yesAnother->textfield->id = 'text11'; $yesAnother->textfield->text = 'omggggg'; $array = array($obj, $anotherObj, $yesAnother); usort($array, function($a, $b) { preg_match_all('#\d+#', $a->textfield->id, $matchesA); preg_match_all('#\d+#', $b->textfield->id, $matchesB); $idNumA = (int)$matchesA[0][0]; $idNumB = (int)$matchesB[0][0]; return $idNumA > $idNumB; }); var_dump($array);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Attempt to assign property "id" on null in /in/l2lcf:4 Stack trace: #0 {main} thrown in /in/l2lcf on line 4
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: Creating default object from empty value in /in/l2lcf on line 4 Warning: Creating default object from empty value in /in/l2lcf on line 8 Warning: Creating default object from empty value in /in/l2lcf on line 12 array(3) { [0]=> object(stdClass)#3 (1) { ["textfield"]=> object(stdClass)#4 (2) { ["id"]=> string(5) "text1" ["text"]=> string(11) "moarrr text" } } [1]=> object(stdClass)#5 (1) { ["textfield"]=> object(stdClass)#6 (2) { ["id"]=> string(6) "text11" ["text"]=> string(7) "omggggg" } } [2]=> object(stdClass)#1 (1) { ["textfield"]=> object(stdClass)#2 (2) { ["id"]=> string(6) "text12" ["text"]=> string(5) "herro" } } }
Output for 5.3.0 - 5.3.29
Strict Standards: Creating default object from empty value in /in/l2lcf on line 4 Strict Standards: Creating default object from empty value in /in/l2lcf on line 8 Strict Standards: Creating default object from empty value in /in/l2lcf on line 12 array(3) { [0]=> object(stdClass)#3 (1) { ["textfield"]=> object(stdClass)#4 (2) { ["id"]=> string(5) "text1" ["text"]=> string(11) "moarrr text" } } [1]=> object(stdClass)#5 (1) { ["textfield"]=> object(stdClass)#6 (2) { ["id"]=> string(6) "text11" ["text"]=> string(7) "omggggg" } } [2]=> object(stdClass)#1 (1) { ["textfield"]=> object(stdClass)#2 (2) { ["id"]=> string(6) "text12" ["text"]=> string(5) "herro" } } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 11 Parse error: syntax error, unexpected T_FUNCTION in /in/l2lcf on line 17
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
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 11 Parse error: parse error, unexpected T_FUNCTION in /in/l2lcf on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/l2lcf on line 11 Parse error: parse error in /in/l2lcf on line 17
Process exited with code 255.

preferences:
235.54 ms | 401 KiB | 307 Q