deleting values in an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

deleting values in an array

Post 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?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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 :)
Post Reply