3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $messageRow = [ 'event_id' => 123, 'event_status' => 50, ]; if (array_key_exists('event_id', $messageRow) && array_key_exists('event_status', $messageRow)) { $id = [ 'event_id' => $messageRow['event_id'], 'event_status' => $messageRow['event_status'], ]; var_dump('A'); } elseif (array_key_exists('event_id', $messageRow)) { $id = $messageRow['event_id']; var_dump('B'); } var_dump($id); echo str_repeat(PHP_EOL, 3) . str_repeat('-', 100) . PHP_EOL; $messageRow = [ 'event_id' => 123, 'event_status' => 50, ]; if (array_key_exists('event_id', $messageRow)) { $id = $messageRow['event_id']; var_dump('C'); } elseif (array_key_exists('event_id', $messageRow) && array_key_exists('event_status', $messageRow)) { $id = [ 'event_id' => $messageRow['event_id'], 'event_status' => $messageRow['event_status'], ]; var_dump('D'); } var_dump($id); echo str_repeat(PHP_EOL, 3) . str_repeat('-', 100) . PHP_EOL; $messageRow = [ 'event_id' => 123, 'event_status' => 50, ]; if (array_key_exists('event_id', $messageRow)) { $id = $messageRow['event_id']; var_dump('E'); } if (array_key_exists('event_id', $messageRow) && array_key_exists('event_status', $messageRow)) { $id = [ 'event_id' => $messageRow['event_id'], 'event_status' => $messageRow['event_status'], ]; var_dump('F'); } var_dump($id);
based on 9tkj9
Output for 5.4.0 - 7.2.6
string(1) "A" array(2) { ["event_id"]=> int(123) ["event_status"]=> int(50) } ---------------------------------------------------------------------------------------------------- string(1) "C" int(123) ---------------------------------------------------------------------------------------------------- string(1) "E" string(1) "F" array(2) { ["event_id"]=> int(123) ["event_status"]=> int(50) }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/2pkil on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/2pkil on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/2pkil on line 4
Process exited with code 255.