Could use array_shift / array_unshift, but since the logic seems upside down, you could use something like
<?php
$apparentDB = array("1" => "Jason" ,
"2" => "Jimmy" ,
"3" => "Christopher" ,
"4" => "Bruce" ,
"5" => "james" ,
"6" => "Mike" ,
"7" => "Brad" );
/* You can add it one by one
$addName = "Walter";
$apparentDB = addName($addName, $apparentDB);
$addSecondName = "Kevin";
$apparentDB = addName($addSecondName, $apparentDB);
*/
// Or you can also modify to work on an array of new names
$newNames = array("Walter", "Kevin");
foreach($newNames as $newName) {
$apparentDB = addName($newName, $apparentDB);
}
var_dump($apparentDB);
function addName($nameToAdd, $apparentDB) {
for ($i = count($apparentDB); $i > 1; $i--) {
$apparentDB["".$i] = $apparentDB["".($i-1)];
}
$apparentDB["1"] = $nameToAdd;
//var_dump($apparentDB);
return $apparentDB;
}
*You can test it here: http://sandbox.onlinephpfunctions.com/ *
2
solved delete the last items of an array [closed]