Re: foreach problem part two [message #184286 is a reply to message #184279] |
Fri, 20 December 2013 06:52 |
Arno Welzel
Messages: 317 Registered: October 2011
Karma:
|
Senior Member |
|
|
richard, 2013-12-20 00:39:
> On Thu, 19 Dec 2013 22:34:24 +0000 (UTC), Doug Miller wrote:
>
>> richard <noreply(at)example(dot)com> wrote in news:oib4w8z2sr5y$.15xxzxjds0xb0$.dlg@
>> 40tude.net:
>>
>>> <?php
>>> foreach ($aname as $item){
>>> echo $aname[$item][1];
>>> echo " (".$aname[$item][2].")";
>>> }
>>> ?>
>>>
>>> I decided to create a second array that holds only the artist and number of
>>> records.
>>> So why am I getting "invalid argument" with this?
>>
>> Because you don't understand how foreach() works. RTFM.
>
> I did.
> 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.
Sigh...
There is no thing like "bracketed arrays" or "standard arrays". This is
called one-dimensional and multi-dimensional. And of course foreach()
works fine with every kind of array.
<?php
$myarray = array(
array( 'Apple', 1 ),
array( 'Pie', 2 )
);
foreach($myarray as $item)
{
echo $item[0] . ' - ' . $item[1] . '<br />';
}
?>
You just don't understand it - as usual.
> While (){}. however works and could care less which is used.
As usual. while() needs more code, is slower and is prone to errors.
Really - software development is not your thing. It seems you are
mentally not capable of understanding the principles.
--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
|
|
|