- array_unshift: documentation ( source)
- array_pop: documentation ( source)
<?php
$notifications = [];
function add($type){
$notify = array(
'text' => $text
, 'link' => $link
, 'img' => $img
, 'context' => $context
);
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< 10; $i++){
add($i);
}