note 33614 added to ref.array
| From: | Jonas at rack1 dot php dot net | Date: | Tue, 01 Jul 2003 22:34:47 +0000 |
| Subject: | note 33614 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51322@lists.php.net to get a copy of this message | ||
A function to remove a row from an array... I couldn't find it in the function list above, or
contributed by any users, so here it is:
// Function requires two arguments: The array you want to remove a row from, and the index of the
row.
function deleterow($array, $index) {
for($i=0; $i<$index; $i++) {
$temp[$i] = $array[$i];
}
for($i=$index+1; $i<count($array); $i++) {
$temp[$i-1] = $array[$i];
}
return $temp;
}
//Use of function - this will remove the second row:
$somearray = deleterow($somearray, 1);
Please note that this functon is as simple as can be, and therefore have no checking. If you put in
an index number larger than the actual number of rows in the array or <0, the function will add
rows to the array.
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33614
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33614&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33614&report=yes