3v4l.org

run code in 300+ PHP versions simultaneously
<?php $notifications = array(); function add($type){ $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); }

preferences:
46.9 ms | 402 KiB | 5 Q