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 #184292 is a reply to message #184285] Fri, 20 December 2013 12:14 Go to previous messageGo to previous message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma:
Senior Member
On 12/19/2013 11:37 PM, Richard Damon wrote:
> On 12/19/13, 11:05 PM, richard wrote:
>> On Fri, 20 Dec 2013 02:09:46 +0100, Christoph Michael Becker 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>
>>
>> As you and others so kindly keep repeating, RTFM!
>>
>> $array[0][0]="data"
>>
>> Is 100% valid!
>>
>> In the arrays manual, it shows the use of bracketed arrays several times.
>> So why don't you tell them they are wrong?
>>
>
> As far as I can tell, the PHP Manual NEVER calls this a "bracketed
> array", and an array created this way is indistinguishable (after
> creation) from the array created with the array() operator.
>
> Creating a previously non-existent member by this member in a previously
> created array does have some advantages.
>
> I will also note, that you original program had no line like this (at
> least that you showed us).
>

This is not 100% legal syntax because the second [0] acts as a string
offset instead of an index:

$alist[0][0] = "data";
Fatal error: Cannot use string offset as an array... you must use
*array()* to set these up.

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[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: Fri Nov 22 04:53:00 GMT 2024

Total time taken to generate the page: 0.04223 seconds