3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $notifications = array(); function add($type){ global $notifications; $notify = array( 'text' => '11' , 'link' => '22' ); if ( $notifications && count($notifications[$type]) <= 4 && count($notifications[$type]) ) { array_unshift($notifications[$type], $notify); } elseif ( $notifications && count($notifications[$type]) > 4 ) { array_pop($notifications[$type]); array_unshift($notifications[$type], $notify); } else { $notifications[$type] = []; array_unshift($notifications[$type], $notify); } } for($i = 0; $i< 2; $i++){ add($i); var_dump($notifications); }
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
array(1) { [0]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } } Notice: Undefined offset: 1 in /in/BvG48 on line 11 Notice: Undefined offset: 1 in /in/BvG48 on line 11 Notice: Undefined offset: 1 in /in/BvG48 on line 16 array(2) { [0]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } [1]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } }
Output for hhvm-3.10.0 - 3.12.0
array(1) { [0]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } } Notice: Undefined index: 1 in /in/BvG48 on line 11 Notice: Undefined index: 1 in /in/BvG48 on line 11 Notice: Undefined index: 1 in /in/BvG48 on line 16 array(2) { [0]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } [1]=> array(1) { [0]=> array(2) { ["text"]=> string(2) "11" ["link"]=> string(2) "22" } } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/BvG48 on line 24
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/BvG48 on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/BvG48 on line 24
Process exited with code 255.