Page 1 of 1

deleting values in an array

Posted: Tue Jul 01, 2003 11:48 am
by gurjit
i have a session array which i declare like this

Code: Select all

<?php
session_register("stuid_list");
?>
i then later add numbers to the session variable making it an array like this:

Code: Select all

<?php
$stuid_list[] = "$sib_stuid";
?>
i need to do two things:


1. how can i go through the array and delete the last 20 entries in the array?

2. how can i go through the array and delete the first 20 entries in the array?

Posted: Tue Jul 01, 2003 12:00 pm
by Stoker
20 at the end
for ($i = 20; $i ; $i--) array_pop ($array);

20 at the beginning
for ($i = 20; $i ; $i--) array_shift ($array);

There may be some other more efficient ways, this was just what I had in my head right now :)