- var_dump: documentation ( source)
- array_unshift: documentation ( source)
- array_pop: documentation ( source)
<?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< 10; $i++){
add($i);
var_dump($notifications);
}