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

Home » Imported messages » comp.lang.php » foreach problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: foreach problem [message #184269 is a reply to message #184267] Thu, 19 December 2013 18:55 Go to previous message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma:
Senior Member
Salvatore wrote:

> On 2013-12-19, richard <noreply(at)example(dot)com> wrote:
>> <?php
>>
>> $alist="$art".$year;
>> $num=0;
>> foreach ($alist as $num){ echo $list[$num++][0]; }
>> ?>
>
> I think you should consider changing the way you write arrays. Instead
> of using "$art60[][]", you could use "$art[60][][]".

ACK

> It also appears
> that you mistyped the variable name in the "foreach" loop -- did you
> mean to type "$alist[$num++][0]"? And why are you incrementing the
> "$num" variable?

Apparently, the problem is not the mistyped variable, but rather the
OP's confusion about foreach loops[1].

> Nevertheless, there *is* a way to do this:
>
> $varname = '$art' . $year; // Note the single quotes.
> $alist = eval("return $varname;");
>
> I don't recommend this, though. It's a security issue.

And most likey rather slow -- and even worse: it's a very confusing way
to do things.

[1] <http://www.php.net/manual/en/control-structures.foreach.php>

--
Christoph M. Becker
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: URL linking to 3d array
Next Topic: working model of the latest project
Goto Forum:
  

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

Current Time: Sun Dec 01 11:17:11 GMT 2024

Total time taken to generate the page: 0.05173 seconds