FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » foreach problem part two
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: foreach problem part two [message #184536 is a reply to message #184281] Tue, 07 January 2014 04:13 Go to previous messageGo to previous message
John Smith is currently offline  John Smith
Messages: 7
Registered: January 2014
Karma:
Junior Member
On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker
<cmbecker69(at)arcor(dot)de> wrote:

> richard wrote:
>
>> There is a flaw in the works that is not discussed.
>> That being, it won't work with brackted arrays.
>> Works fine with standard arrays.
>
> Nonsense. PHP has only one array type.[1]
>
>> While (){}. however works and could care less which is used.
>
> Assume, you have an array:
>
> $array = array('one', 'two', 'three');
>
> Now you want to echo its elements in order. What is simpler and more
> readable?
>
> $i = 0;
> while ($i < count($array)) {
> echo $array[$i];
> }
>
> or
>
> foreach ($array as $element) {
> echo $element;
> }
>
> Additionally, the foreach loop is most likely faster.
>
> [1] <http://www.php.net/manual/en/language.types.array.php>

At the first example you don't have to increment the $i?

John
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP sql entry is a godaweful mess
Next Topic: Math Formula Question - Need Ideas
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 16:57:00 GMT 2024

Total time taken to generate the page: 0.04274 seconds