Re: end of array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"M. Sokolewicz" <tularis@xxxxxxx> writes:

> Raj Shekhar wrote:
> > "M. Sokolewicz" <tularis@xxxxxxx> writes:
> >
> >>Raj Shekhar wrote:
> >
> >>>$n_elts = count($myarray);
> >>>for ($i=0; $i< $n_elts ; $i++)
> >>>{
> >>>        if ($i = $n_elts -1)
> >                   ^^^
> > Use of == required to make it work
> >>>        {
> >>>                echo "On last element";
> >>>                break;
> >>>        }
> >>>        else
> >>>        {
> >>>                echo "Somwhere in the middle";
> >>>        }
> >>>}
> >>
> >>that's an eternal loop in case you hadn't noticed (*rolls eyes*)
> > Oops :( not eternal loop though, only one loop
> why one?
> for($i=0; $i<$n;$i++) {
> 	$i = ($n-1);
> }

My statement was, 

if ($i = $n_elts -1)

{
        echo "On last element";
        break;
}

i.e.

- assign ($i = $n_elts -1) and check the return value of the
  assignment. 

- If the assignment succeeds (which should, unless you are running
  short of free memory) THEN

	- echo 
        - BREAK out of loop 

Since this conditions are met the first time the loop runs, the loop
will run only once. I know I am correct, since I ran the code this
time :P

-- 
Raj Shekhar
System Administrator, programmer and  slacker
home : http://rajshekhar.net
blog : http://rajshekhar.net/blog/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux