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

Home » Imported messages » comp.lang.php » foreach problem
Show: Today's Messages :: Unread Messages :: Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
foreach problem [message #184265] Thu, 19 December 2013 12:42 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
<?php

$alist="$art".$year;
$num=0;
foreach ($alist as $num){ echo $list[$num++][0]; }
?>


my bracketed arrays are designed with $art60[][] format.
where "60" will change with the given year.
Using the above script, I get "invalid argument".
So what would be a valid argument?

The array is setup so that $art60[number][0]=artist name (always).
then each record for that artist is listed in 3d format.
$art60[number][record]['info']="data".


I want to list just the artist names in one division.

http://mroldies.net/artists/art60.php
not that you'll see anything right now.
Re: foreach problem [message #184266 is a reply to message #184265] Thu, 19 December 2013 13:06 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
remove from buddy list
ignore all messages by this user
In article <4crg8sz8mnlg(dot)kvx5ofaf71nu(dot)dlg(at)40tude(dot)net>, richard
<noreply(at)example(dot)com> wrote:

> <?php
>
> $alist="$art".$year;
> $num=0;
> foreach ($alist as $num){ echo $list[$num++][0]; }
> ?>
>
>
> my bracketed arrays are designed with $art60[][] format.
> where "60" will change with the given year.
> Using the above script, I get "invalid argument".
> So what would be a valid argument?
>
> The array is setup so that $art60[number][0]=artist name (always).
> then each record for that artist is listed in 3d format.
> $art60[number][record]['info']="data".

Is alist an array, like it says in the foreach doccy? And why are you
incrementing $num ?

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: foreach problem [message #184267 is a reply to message #184265] Thu, 19 December 2013 13:09 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
add to buddy list
ignore all messages by this user
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][][]". 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?

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.

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Message by Christoph Michael Bec is ignored  [reveal message]  [reveal all messages by Christoph Michael Bec]  [stop ignoring this user] Go to previous messageGo to next message
Re: foreach problem [message #184271 is a reply to message #184266] Thu, 19 December 2013 14:13 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
remove from buddy list
ignore all messages by this user
On Thu, 19 Dec 2013 18:06:51 +0000, Tim Streater wrote:

> [1] Is alist an array, like it says in the foreach doccy? [2] And why
are you
> incrementing $num ?

[1] Probably not
[2] Because he's richard

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Message by The Natural Philosoph is ignored  [reveal message]  [reveal all messages by The Natural Philosoph]  [stop ignoring this user] Go to previous messageGo to next message
Message by The Natural Philosoph is ignored  [reveal message]  [reveal all messages by The Natural Philosoph]  [stop ignoring this user] Go to previous message
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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 Apr 20 16:11:57 EDT 2025

Total time taken to generate the page: 0.04375 seconds