3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ [ 'lang' => 'de', 'value' => "text_1_en_Text i need", 'id' => 2365 ], [ 'lang' => 'en', 'value' => "something i dont need", 'id' => 2365 ] ]; $needle = 'text_1_en_'; var_export( array_filter( $array, fn($row) => str_starts_with($row['value'], $needle) ) ); echo "\n---\n"; $result = []; foreach ($array as $row) { if (str_starts_with($row['value'], $needle)) { $result = $row; break; } } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
array ( 0 => array ( 'lang' => 'de', 'value' => 'text_1_en_Text i need', 'id' => 2365, ), ) --- array ( 'lang' => 'de', 'value' => 'text_1_en_Text i need', 'id' => 2365, )
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Call to undefined function str_starts_with() in /in/FdEBu:20 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/FdEBu(21): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/FdEBu on line 20
Process exited with code 255.

preferences:
98.69 ms | 1285 KiB | 4 Q