3v4l.org

run code in 300+ PHP versions simultaneously
<?php function errorHandler($con) { $body = match($con) { 'id' => 'there was no id', 'name' => 'there was no name', 'age' => 'there was no age', 'age' => 'all good', default => '' }; echo "<h1>$body</h1>"; return (bool) $body; } $Array = [ ['data1' => 1, 'data2' => 0, 'data3' => 1] ]; foreach ($Array as ['data1' => $Id, 'data2' => $name, 'data3' => $age]) { if (!$Id) { if (errorHandler('id')) { break; } } elseif (!$name) { if (errorHandler('name')) { break; } } elseif (!$age) { if (errorHandler('age')) { break; } } else { if (errorHandler('good')) { break; } } echo "UserId $Id, Name = $name, Age = $age<br>"; }
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.18, 8.5.0 - 8.5.3
<h1>there was no name</h1>
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/8m9K5 on line 5
Process exited with code 255.

preferences:
89.84 ms | 1238 KiB | 4 Q