3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
57.04 ms | 402 KiB | 5 Q