Re: ARRAY Question!
| From: | Aidal | Date: | Wed, 05 Mar 2003 07:33:58 +0000 |
| Subject: | Re: ARRAY Question! | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-18848@lists.php.net to get a copy of this message | ||
Hmm.. When using arrays with loops a for structure comes in handy.
$count = sizeof($yourArray);
For ($i = 0; $i < $count; $i++) {
...do somthing...
... do some more...
}
Remember that index of arrays start at 0 and not at 1, so if you want to add
a value to the end of the array you can just add it like this:
$yourArray[$count] = "whatever value you want";
Since sizeof() returns the number of elements in your array and an array
starts at 0, the return value of sizeof($yourArray), if it contains 5
elements, would be 5.
But the index goes from 0 to 4 so adding an item to $yourArray[$count],
would be adding it to the end aka $yourArray[5].
/Aidal
"Matt Babineau" <matt@criticalcode.com> wrote in message
news:007c01c2e29b$d0f7e370$6610a8c0@webdevx...
> It's a numerical key so $myArray[] = "value"; will work perfectly!
>
> Thanks!
>
> --> -----Original Message-----
> --> From: Ben O'Neill [mailto:boneill@nphp.net]
> --> Sent: Tuesday, March 04, 2003 5:06 PM
> --> To: php-windows@lists.php.net
> --> Subject: Re: [PHP-WIN] ARRAY Question!
> -->
> -->
> --> Using that it would be:
> -->
> --> $array_length = count($myArray);
> --> $myArray[$array_length] = $new_data;
> -->
> --> As arrays start at 0, and count() returns the number of elements.
> -->
> --> - Ben O'Neill
> -->
> --> "Chris Kranz" <chris@kranz.com> wrote in message
> news:008001c2e299$79612b00$8362883e@littleskate...
> > Something like...
> >
> > $array_length = count( $myArray );
> > $myArray[$array_length + 1] = $new_data;
> >
> > This what your after? I think there might be a function for this tho,
> > but I'm a bit thick :p
> >
> > chris kranz
> > fatcuban.com
> >
> >
> >
> > -----Original Message-----
> > From: Matt Babineau [mailto:matt@criticalcode.com]
> > Sent: 04 March 2003 21:55
> > To: php-windows@lists.php.net
> > Subject: [PHP-WIN] ARRAY Question!
> >
> >
> > Ok here goes!
> >
> > Lets say I have an array:
> >
> > $myArray = array();
> >
> > Now lets say I am looping over something
> >
> >
> > <LOOP>
> >
> > How do I simply add a new value to the array??
> >
> > I just want to start tacking on new key/value pairs to the array.
> >
> > I must be missing something really basic, but I'm not getting it LOL.
> >
> > <END LOOP>
> >
> >
> > Thanks,.
> >
> > <MAtt>
> >
> >
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>