Re: Help with arrays?
- From: "Mike G." <mgirouard@xxxxxxxxx>
- Date: 24 Aug 2006 11:18:21 -0700
I use in_array() all the time:
<?php
$delete_me = 'Red'; // the value we want to remove...
$colors = array('Red', 'Green', 'Blue', 'Clear');
if(in_array($delete_me,$colors)) {
unset($colors[array_search($delete_me,$colors)]);
}
?>
Flaming Corncob wrote:
In article <9c30f$44ed965b$8259c69c$3516@xxxxxxxxxxxxxxxx>,
"Rik" <luiheidsgoeroe@xxxxxxxxxxx> wrote:
Flaming Corncob wrote:
Is there any way to add to an already existing array?
Several, for instance:
1. $array[] = $value;
Will add a numerically indexed value on the end of the array
2. array_push($array, $foo, $bar,...);
Will add an arbitrary amount of variables to the end of the array
3. array_unshift($arraym$foo,$bar,....);
Same as array_push, only to the beginning
And many, many more possibilities, read up on it:
http://www.php.net/manual/en/ref.array.php
http://www.php.net/manual/en/language.types.array.php
Cool. Already stumbled on array_push() but $array is easier. Next I need
to be able to find something in an array and if it's there erase it.
I've tried unset() but that destroys part of the array and when you add
to it after that it doesn't fill in the hole created by unset..
.
- References:
- Help with arrays?
- From: Flaming Corncob
- Re: Help with arrays?
- From: Rik
- Re: Help with arrays?
- From: Flaming Corncob
- Help with arrays?
- Prev by Date: Re: Uploading JPG's
- Next by Date: Re: How many types of error massages in php?
- Previous by thread: Re: Help with arrays?
- Next by thread: Regex question, Text in brackets?
- Index(es):
Relevant Pages
|