Try this I think it will work.

$count = count($arry);

for ($i=0; $i<$count; $i++) {
   // do something with $array[$i]
}

cout($array) brings back the number of elements in the array which limits
the lookup index.



-----Original Message-----
From: Rick Emery [mailto:[EMAIL PROTECTED]
Sent: Friday, June 17, 2005 2:30 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Problem with array


Quoting Ross <[EMAIL PROTECTED]>:

> As with my previous post the problem is the pieces of the array can vary
> from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
> 'undefined index' notice. All I really want to do is display the array
> pieces if they EXIST. But as they are inside a echo statement so I can't
> even to a for loop...can I?

Not sure about a "for" loop inside the "echo".

> Any ideas?

Yes. Something like this should work:

echo "<beginning html tags>";
foreach ($pieces as $this_piece) {
   echo $this_piece . " ";
}
echo "<middle html tags>";
echo $formatted_price;
echo "<closing html tags>";

This should at least give you a starting point. I'm fairly new to php,
so maybe one of the gurus will give a better idea (or explain why mine
won't work, if it won't).

hth,
Rick

P.S. I would usually trim out the rest of the message, but am leaving
the code below as reference. Sorry for the long post.

> if ($quantity == 0){
>
>    }
>   else {
>
> $pieces = explode(" ", $quantity);
>
>
>   $formatted_price = sprintf('%0.2f', $pricecode);
>  echo "<table width=\"240\" border=\"0\" cellpadding=\"2\"
> cellspacing=\"5\"><tr><td valign=\"top\" align=\"right\"
> width=\"40\">$pieces[0]</td><td align=\"left\" width=\"60\"></td><td
> align=\"left\" width=\"200\">$pieces[1]  $pieces[2] $pieces[3]
> $pieces[4]</td><td valign=\"top\" align=\"left\"
> width=\"80\">$formatted_price</td></tr></table>";
>
>
>
>
>
>   }
>   }

--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
                                              -- Leonardo Da Vinci

--
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

Reply via email to