Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12302 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2013-12-19 12:42 -0500 |
| Last post | 2013-12-19 19:55 +0100 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.php
foreach problem richard <noreply@example.com> - 2013-12-19 12:42 -0500
Re: foreach problem Tim Streater <timstreater@greenbee.net> - 2013-12-19 18:06 +0000
Re: foreach problem Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-19 19:13 +0000
Re: foreach problem The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:19 +0000
Re: foreach problem The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:19 +0000
Re: foreach problem Salvatore <sal@yojimbo.hack.invalid> - 2013-12-19 18:09 +0000
Re: foreach problem Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-19 19:55 +0100
| From | richard <noreply@example.com> |
|---|---|
| Date | 2013-12-19 12:42 -0500 |
| Subject | foreach problem |
| Message-ID | <4crg8sz8mnlg.kvx5ofaf71nu.dlg@40tude.net> |
<?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.
[toc] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2013-12-19 18:06 +0000 |
| Message-ID | <191220131806517838%timstreater@greenbee.net> |
| In reply to | #12302 |
In article <4crg8sz8mnlg.kvx5ofaf71nu.dlg@40tude.net>, richard
<noreply@example.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
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-12-19 19:13 +0000 |
| Message-ID | <l8vgg4$hhm$1@dont-email.me> |
| In reply to | #12303 |
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@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-12-19 19:19 +0000 |
| Message-ID | <l8vgs1$hpv$2@news.albasani.net> |
| In reply to | #12308 |
On 19/12/13 19:13, Denis McMahon wrote: > 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 > +100 -- Ineptocracy (in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-12-19 19:19 +0000 |
| Message-ID | <l8vgra$hpv$1@news.albasani.net> |
| In reply to | #12303 |
On 19/12/13 18:06, Tim Streater wrote:
> In article <4crg8sz8mnlg.kvx5ofaf71nu.dlg@40tude.net>, richard
> <noreply@example.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 ?
>
Its richard. The question will make no sense.
Killfile.
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | Salvatore <sal@yojimbo.hack.invalid> |
|---|---|
| Date | 2013-12-19 18:09 +0000 |
| Message-ID | <l8vcom$4ro$1@news.tokachu.com> |
| In reply to | #12302 |
On 2013-12-19, richard <noreply@example.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++
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-12-19 19:55 +0100 |
| Message-ID | <52b3412c$0$9521$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #12304 |
Salvatore wrote:
> On 2013-12-19, richard <noreply@example.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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web