Re: makeing an array
| From: | Timothy Hitchens \(HiTCHO\) | Date: | Wed, 01 Jan 2003 12:00:15 +0000 |
| Subject: | Re: makeing an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-129841@lists.php.net to get a copy of this message | ||
Your example of:
for ($i = 0; $i < count($comment); $i++)
Is very bad as the count will be parsed each loop.
The count as I had it gets parsed only once.
Timothy Hitchens (HiTCHO)
tim@hitcho.com.au
HiTCHO | Open Platform Web Development
Consulting - Outsourcing - Training - Support
----- Original Message -----
From: "Sean Malloy" <sean@element.net.au>
To: <php-general@lists.php.net>
Sent: Wednesday, January 01, 2003 9:40 PM
Subject: RE: [PHP] makeing an array
> why the $x variable aswell?!
>
> for ($i = 0; $i < count($comment); $i++)
> {
> echo $comment[$i].'<br />';
> }
>
> or even faster:
>
> $i = count($comment);
> while ($i--)
> {
> echo $comment[$i].'<br />';
> }
>
> > -----Original Message-----
> > From: Timothy Hitchens (HiTCHO) [mailto:phplists@hitcho.com.au]
> > Sent: Wednesday, 1 January 2003 4:41 PM
> > To: Philip J. Newman; php-general@lists.php.net
> > Subject: Re: [PHP] makeing an array
> >
> >
> > Use the count like following inside to ensure that you don't
> > call on a non existent index.
> >
> > for ($i = 0, $x = count($comment); $i < $x; $i++)
> > {
> > echo $comment[$i].'<br />';
> > }
> >
> > Why do you want to echo out $comment_1 ???
> >
> >
> >
> > Timothy Hitchens (HiTCHO)
> > tim@hitcho.com.au
> >
> >
> > HiTCHO | Open Platform Web Development
> > Consulting - Outsourcing - Training - Support
> >
> >
> > ----- Original Message -----
> > From: "Philip J. Newman" <newmanpj@philipnz.com>
> > To: "Timothy Hitchens (HiTCHO)" <phplists@hitcho.com.au>;
> > <php-general@lists.php.net>
> > Sent: Wednesday, January 01, 2003 3:29 PM
> > Subject: Re: [PHP] makeing an array
> >
> >
> > > So in saything that I could do this ...
> > >
> > > $s = 10
> > >
> > > $comment[1] = '$comment_1';
> > > $comment[2] = '$comment_2';
> > > $comment[3] = '$comment_2';
> > >
> > > for($i = 0; $i <= $s; $i++) {
> > >
> > > echo $comment[$i]."<br>";
> > >
> > > }
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Timothy Hitchens (HiTCHO)" <phplists@hitcho.com.au>
> > > To: "Philip J. Newman" <newmanpj@philipnz.com>;
> > <php-general@lists.php.net>
> > > Sent: Wednesday, January 01, 2003 6:12 PM
> > > Subject: Re: [PHP] makeing an array
> > >
> > >
> > > > Example of an Array:
> > > >
> > > > $my_first_array = array(1 => 'first', 2 => 'second', 3
> > > > => 'third');
> > > >
> > > > You can now access these like so:
> > > >
> > > > echo $my_first_array[1]; etc etc
> > > >
> > > > of if you had this: $my_first_array = array('first_name' =>
'Philip',
> > > > 'last_name' => 'Newman');
> > > >
> > > > You could do this:
> > > >
> > > > echo $my_first_array['first_name'];
> > > >
> > > > The thing to remember is that array's start at 0 "see below!!" (I
> > started
> > > at
> > > > 1 at the top to make it easier).
> > > >
> > > > You can also make an array like so:
> > > >
> > > > $first[] = 'Philip';
> > > > $first[] = 'John';
> > > > $first[] = 'Paul';
> > > >
> > > > Now you can simply do:
> > > >
> > > > echo $first[0]; // this could output 'Philip';
> > > >
> > > > You can then look at multi dimensional etc...
> > > >
> > > > I trust this get's you on your way.
> > > >
> > > >
> > > > Timothy Hitchens (HiTCHO)
> > > > tim@hitcho.com.au
> > > >
> > > >
> > > > HiTCHO | Open Platform Web Development
> > > > Consulting - Outsourcing - Training - Support
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Philip J. Newman" <newmanpj@philipnz.com>
> > > > To: <php-general@lists.php.net>
> > > > Sent: Wednesday, January 01, 2003 2:57 PM
> > > > Subject: [PHP] makeing an array
> > > >
> > > >
> > > > > Can someone help me make an array ...
> > > > >
> > > > > I have $foo amount of loops to preform (1-20), and would
> > like to make
> > > the
> > > > > veriable work for me like $comment_1, $comment_2 etc etc.
> > > > >
> > > > >
> > > > > http://nz.php.net/manual/en/function.array.php makes no sence to
me
> > > after
> > > > i
> > > > > read it and read it ...
> > > > >
> > > > > help me please
> > > > >
> > > > > ---
> > > > > Philip J. Newman.
> > > > > Head Developer.
> > > > > PhilipNZ.com New Zealand Ltd.
> > > > > http://www.philipnz.com/
> > > > > info@philipnz.com
> > > > >
> > > > > Mob: +64 (25) 6144012.
> > > > > Tele: +64 (9) 5769491.
> > > > >
> > > > > VitalKiwi Site:
> > > > > Philip J. Newman
> > > > > Internet Developer
> > > > > http://www.newman.net.nz/
> > > > > info@newman.net.nz
> > > > >
> > > > > *****************************
> > > > > Friends are like Stars,
> > > > > You can't always see them,
> > > > > But you know they are there.
> > > > >
> > > > > *****************************
> > > > >
> > > > > ICQ#: 20482482
> > > > > MSN ID: philipsdomain@hotmail.com
> > > > > Yahoo: philip_newman@yahoo.com
> > > > > AIM: newmanpjkiwi
> > > > >
> > > > >
> > > > > --
> > > > > PHP General Mailing List (http://www.php.net/)
> > > > > To unsubscribe, visit: Èáùï3
> > > > > **GÞ€konhttp://www.php.net/unsub.php
> > > > >
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit:
> > > > http://www.php.net/unsub.php
> > > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>