Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8569 > unrolled thread

returning values from a 2d array

Started byrichard <noreply@example.com>
First post2013-03-07 10:49 -0500
Last post2013-03-07 15:00 -0700
Articles 9 — 4 participants

Back to article view | Back to comp.lang.php


Contents

  returning values from a 2d array richard <noreply@example.com> - 2013-03-07 10:49 -0500
    Re: returning values from a 2d array Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-07 11:26 -0500
      Re: returning values from a 2d array richard <noreply@example.com> - 2013-03-07 11:31 -0500
        Re: returning values from a 2d array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-07 17:50 +0100
        Re: returning values from a 2d array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-07 18:02 +0100
        Re: returning values from a 2d array Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-07 14:41 -0500
    Re: returning values from a 2d array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-07 17:48 +0100
      Re: returning values from a 2d array richard <noreply@example.com> - 2013-03-07 12:04 -0500
    Re: returning values from a 2d array Alastair Black <abqab.nemo@example.net> - 2013-03-07 15:00 -0700

#8569 — returning values from a 2d array

Fromrichard <noreply@example.com>
Date2013-03-07 10:49 -0500
Subjectreturning values from a 2d array
Message-ID<ewh1yyqb5sh0$.1ff3g2zafy3ux$.dlg@40tude.net>
I have been searching the web for an answer but can't really find what I
want to know.

How do I retrieve the values from an array once the random number has been
generated?
In BASIC, one would simply say: show$=top$(1960,1).
In PHP though, it seems you have to go through a miriad of loops just to
find out if the value exists.

So how is this done properly?


<?php 

anum=rand(1,40);   
$num=anum
$number="0" . $num;
if ($num<10) {$number="0" . $number;}
if (Snum>=100) {$number=$num;}

$top[1960][0]= array("top 100 1960");
$top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");
$top[1960][2]= array("He'll Have To Go "," In A Mansion Stands My Love ","
Jim Reeves "," RCA Victor 7643 "," Composer: J. Allison, A. Allison ","
Arranger: "," Producer: Chet Atkins "," Composer: Johnny Russell ","
Arranger: "," Producer: Chet Atkins ");
$top[1960][3]= array("Cathy's Clown "," Always It's You "," Everly Brothers
"," Warner Bros. 5151 "," Composer: Don Everly, Phil Everly "," Arranger:
"," Producer: "," Composer: B. Bryant, F. Bryant "," Arranger: ","
Producer: ");
$top[1960][4]= array("Running Bear "," My Heart Knows "," Johnny Preston
"," Merucry 71474 "," Composer: J. P. Richardson "," Arranger: ","
Producer: "," Composer: J. P. Richardson, J. Preston "," Arranger: ","
Producer: ");
$top[1960][5]= array("Teen Angel "," Bye Now Baby "," Mark Dinning "," MGM
12845 "," Composer: J. Surrey, R. Surrey "," Arranger: "," Producer: ","
Composer: Bryant "," Arranger: "," Producer: ");

[toc] | [next] | [standalone]


#8570

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-07 11:26 -0500
Message-ID<khaf0m$bs1$1@dont-email.me>
In reply to#8569
On 3/7/2013 10:49 AM, richard wrote:
> I have been searching the web for an answer but can't really find what I
> want to know.
>
> How do I retrieve the values from an array once the random number has been
> generated?
> In BASIC, one would simply say: show$=top$(1960,1).
> In PHP though, it seems you have to go through a miriad of loops just to
> find out if the value exists.
>
> So how is this done properly?
>
>
> <?php
>
> anum=rand(1,40);
> $num=anum
> $number="0" . $num;
> if ($num<10) {$number="0" . $number;}
> if (Snum>=100) {$number=$num;}
>
> $top[1960][0]= array("top 100 1960");
> $top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
> Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
> Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");
> $top[1960][2]= array("He'll Have To Go "," In A Mansion Stands My Love ","
> Jim Reeves "," RCA Victor 7643 "," Composer: J. Allison, A. Allison ","
> Arranger: "," Producer: Chet Atkins "," Composer: Johnny Russell ","
> Arranger: "," Producer: Chet Atkins ");
> $top[1960][3]= array("Cathy's Clown "," Always It's You "," Everly Brothers
> "," Warner Bros. 5151 "," Composer: Don Everly, Phil Everly "," Arranger:
> "," Producer: "," Composer: B. Bryant, F. Bryant "," Arranger: ","
> Producer: ");
> $top[1960][4]= array("Running Bear "," My Heart Knows "," Johnny Preston
> "," Merucry 71474 "," Composer: J. P. Richardson "," Arranger: ","
> Producer: "," Composer: J. P. Richardson, J. Preston "," Arranger: ","
> Producer: ");
> $top[1960][5]= array("Teen Angel "," Bye Now Baby "," Mark Dinning "," MGM
> 12845 "," Composer: J. Surrey, R. Surrey "," Arranger: "," Producer: ","
> Composer: Bryant "," Arranger: "," Producer: ");
>

$top is a three dimensional array and would be indexed as
$top[$x][$y][$z].  For instance, "Theme From a Summer Place" would be 
$top[1960][1][0] and "Composer: J. P. Richardson" would be
$top[1960][4][4].

I think you're going about this the wrong way, but hey - it's your code.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8571

Fromrichard <noreply@example.com>
Date2013-03-07 11:31 -0500
Message-ID<1ia4fx4xt4z60$.1wcv8sw6oujxf$.dlg@40tude.net>
In reply to#8570
On Thu, 07 Mar 2013 11:26:18 -0500, Jerry Stuckle wrote:

> On 3/7/2013 10:49 AM, richard wrote:
>> I have been searching the web for an answer but can't really find what I
>> want to know.
>>
>> How do I retrieve the values from an array once the random number has been
>> generated?
>> In BASIC, one would simply say: show$=top$(1960,1).
>> In PHP though, it seems you have to go through a miriad of loops just to
>> find out if the value exists.
>>
>> So how is this done properly?
>>
>>
>> <?php
>>
>> anum=rand(1,40);
>> $num=anum
>> $number="0" . $num;
>> if ($num<10) {$number="0" . $number;}
>> if (Snum>=100) {$number=$num;}
>>
>> $top[1960][0]= array("top 100 1960");
>> $top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
>> Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
>> Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");
>> $top[1960][2]= array("He'll Have To Go "," In A Mansion Stands My Love ","
>> Jim Reeves "," RCA Victor 7643 "," Composer: J. Allison, A. Allison ","
>> Arranger: "," Producer: Chet Atkins "," Composer: Johnny Russell ","
>> Arranger: "," Producer: Chet Atkins ");
>> $top[1960][3]= array("Cathy's Clown "," Always It's You "," Everly Brothers
>> "," Warner Bros. 5151 "," Composer: Don Everly, Phil Everly "," Arranger:
>> "," Producer: "," Composer: B. Bryant, F. Bryant "," Arranger: ","
>> Producer: ");
>> $top[1960][4]= array("Running Bear "," My Heart Knows "," Johnny Preston
>> "," Merucry 71474 "," Composer: J. P. Richardson "," Arranger: ","
>> Producer: "," Composer: J. P. Richardson, J. Preston "," Arranger: ","
>> Producer: ");
>> $top[1960][5]= array("Teen Angel "," Bye Now Baby "," Mark Dinning "," MGM
>> 12845 "," Composer: J. Surrey, R. Surrey "," Arranger: "," Producer: ","
>> Composer: Bryant "," Arranger: "," Producer: ");
>>
> 
> $top is a three dimensional array and would be indexed as
> $top[$x][$y][$z].  For instance, "Theme From a Summer Place" would be 
> $top[1960][1][0] and "Composer: J. P. Richardson" would be
> $top[1960][4][4].
> 
> I think you're going about this the wrong way, but hey - it's your code.

Not according to the PHP manual.
I have seen the format I'm using online and have tested it.
I tried using $a=$top[1960][anum] and the output was "Array".

[toc] | [prev] | [next] | [standalone]


#8573

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-03-07 17:50 +0100
Message-ID<apruq9F1d1iU2@mid.uni-berlin.de>
In reply to#8571
Am 07.03.2013 17:31, schrieb richard:
> On Thu, 07 Mar 2013 11:26:18 -0500, Jerry Stuckle wrote:

>> I think you're going about this the wrong way, but hey - it's your code.
> 
> Not according to the PHP manual.
> I have seen the format I'm using online and have tested it.
> I tried using $a=$top[1960][anum] and the output was "Array".

What is anum supposed to be? It is not an index. Turn on all error reporting options.

/Str.

[toc] | [prev] | [next] | [standalone]


#8574

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-03-07 18:02 +0100
Message-ID<aprvgdF1j4iU1@mid.uni-berlin.de>
In reply to#8571
Am 07.03.2013 17:31, schrieb richard:
> On Thu, 07 Mar 2013 11:26:18 -0500, Jerry Stuckle wrote:
> 
>> On 3/7/2013 10:49 AM, richard wrote:
>>> I have been searching the web for an answer but can't really find what I
>>> want to know.
>>>
>>> How do I retrieve the values from an array once the random number has been
>>> generated?
>>> In BASIC, one would simply say: show$=top$(1960,1).
>>> In PHP though, it seems you have to go through a miriad of loops just to
>>> find out if the value exists.
>>>
>>> So how is this done properly?
>>>
>>
>> $top is a three dimensional array and would be indexed as
>> $top[$x][$y][$z].  For instance, "Theme From a Summer Place" would be 
>> $top[1960][1][0] and "Composer: J. P. Richardson" would be
>> $top[1960][4][4].
>>
>> I think you're going about this the wrong way, but hey - it's your code.
> 
> Not according to the PHP manual.
> I have seen the format I'm using online and have tested it.
> I tried using $a=$top[1960][anum] and the output was "Array".
> 

Listen to what people are telling you, or stop asking. Of course $top[1960][$anum] is
an array, you assigned it yourself:

$top[1960][2]= array("He'll H....

You have 3 index levels.

/Str.

[toc] | [prev] | [next] | [standalone]


#8577

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-03-07 14:41 -0500
Message-ID<khaqe6$j6q$1@dont-email.me>
In reply to#8571
On 3/7/2013 11:31 AM, richard wrote:
> On Thu, 07 Mar 2013 11:26:18 -0500, Jerry Stuckle wrote:
>
>> On 3/7/2013 10:49 AM, richard wrote:
>>> I have been searching the web for an answer but can't really find what I
>>> want to know.
>>>
>>> How do I retrieve the values from an array once the random number has been
>>> generated?
>>> In BASIC, one would simply say: show$=top$(1960,1).
>>> In PHP though, it seems you have to go through a miriad of loops just to
>>> find out if the value exists.
>>>
>>> So how is this done properly?
>>>
>>>
>>> <?php
>>>
>>> anum=rand(1,40);
>>> $num=anum
>>> $number="0" . $num;
>>> if ($num<10) {$number="0" . $number;}
>>> if (Snum>=100) {$number=$num;}
>>>
>>> $top[1960][0]= array("top 100 1960");
>>> $top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
>>> Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
>>> Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");
>>> $top[1960][2]= array("He'll Have To Go "," In A Mansion Stands My Love ","
>>> Jim Reeves "," RCA Victor 7643 "," Composer: J. Allison, A. Allison ","
>>> Arranger: "," Producer: Chet Atkins "," Composer: Johnny Russell ","
>>> Arranger: "," Producer: Chet Atkins ");
>>> $top[1960][3]= array("Cathy's Clown "," Always It's You "," Everly Brothers
>>> "," Warner Bros. 5151 "," Composer: Don Everly, Phil Everly "," Arranger:
>>> "," Producer: "," Composer: B. Bryant, F. Bryant "," Arranger: ","
>>> Producer: ");
>>> $top[1960][4]= array("Running Bear "," My Heart Knows "," Johnny Preston
>>> "," Merucry 71474 "," Composer: J. P. Richardson "," Arranger: ","
>>> Producer: "," Composer: J. P. Richardson, J. Preston "," Arranger: ","
>>> Producer: ");
>>> $top[1960][5]= array("Teen Angel "," Bye Now Baby "," Mark Dinning "," MGM
>>> 12845 "," Composer: J. Surrey, R. Surrey "," Arranger: "," Producer: ","
>>> Composer: Bryant "," Arranger: "," Producer: ");
>>>
>>
>> $top is a three dimensional array and would be indexed as
>> $top[$x][$y][$z].  For instance, "Theme From a Summer Place" would be
>> $top[1960][1][0] and "Composer: J. P. Richardson" would be
>> $top[1960][4][4].
>>
>> I think you're going about this the wrong way, but hey - it's your code.
>
> Not according to the PHP manual.
> I have seen the format I'm using online and have tested it.
> I tried using $a=$top[1960][anum] and the output was "Array".
>

Your code does not match what's in the manual.  That's why you get 
"Array" as the output.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8572

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-03-07 17:48 +0100
Message-ID<aprumgF1d1iU1@mid.uni-berlin.de>
In reply to#8569
Am 07.03.2013 16:49, schrieb richard:
> I have been searching the web for an answer but can't really find what I
> want to know.
> 
> How do I retrieve the values from an array once the random number has been
> generated?
> In BASIC, one would simply say: show$=top$(1960,1).
> In PHP though, it seems you have to go through a miriad of loops just to
> find out if the value exists.
> 
> So how is this done properly?
> 
> 
> <?php 
> 
> anum=rand(1,40); 
Error, missing $

> $num=anum
Error, missing ;
> $number="0" . $num;
Looks like nonsens.
> if ($num<10) {$number="0" . $number;}
> if (Snum>=100) {$number=$num;}
> 
> $top[1960][0]= array("top 100 1960");
> $top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
> Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
> Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");

What are you trying to do? Pick one song randomly?

Then look at your array:

echo $top[1960][1][0] would give "Theme From A Summer Place"

Just put rand(0,9) as index of the third level, and the rest ... don't know what you
want.

And it is quite near to PHP array abuse, there must be a better representation.

/Str.

[toc] | [prev] | [next] | [standalone]


#8575

Fromrichard <noreply@example.com>
Date2013-03-07 12:04 -0500
Message-ID<1td28t0uxvtuh$.tihnteps3yk3.dlg@40tude.net>
In reply to#8572
On Thu, 07 Mar 2013 17:48:16 +0100, M. Strobel wrote:

> Am 07.03.2013 16:49, schrieb richard:
>> I have been searching the web for an answer but can't really find what I
>> want to know.
>> 
>> How do I retrieve the values from an array once the random number has been
>> generated?
>> In BASIC, one would simply say: show$=top$(1960,1).
>> In PHP though, it seems you have to go through a miriad of loops just to
>> find out if the value exists.
>> 
>> So how is this done properly?
>> 
>> 
>> <?php 
>> 
>> anum=rand(1,40); 
> Error, missing $
> 
>> $num=anum
> Error, missing ;
>> $number="0" . $num;
> Looks like nonsens.
>> if ($num<10) {$number="0" . $number;}
>> if (Snum>=100) {$number=$num;}
>> 
>> $top[1960][0]= array("top 100 1960");
>> $top[1960][1]= array("Theme From A Summer Place "," Go-Go-Po-Go "," Percy
>> Faith "," Columbia 41490 "," Composer: Max Steiner"," Arranger: ","
>> Producer: "," Composer: Percy Faith "," Arranger: "," Producer: ");
> 
> What are you trying to do? Pick one song randomly?
> 
> Then look at your array:
> 
> echo $top[1960][1][0] would give "Theme From A Summer Place"
> 
> Just put rand(0,9) as index of the third level, and the rest ... don't know what you
> want.
> 
> And it is quite near to PHP array abuse, there must be a better representation.
> 
> /Str.

the randomizing feature works quite well.
www.mroldies.net/playertest.php
which randomly selects one of 40 songs each time the page is reloaded.

what I am wanting to do is, print the information for the song below the
player.

[toc] | [prev] | [next] | [standalone]


#8581

FromAlastair Black <abqab.nemo@example.net>
Date2013-03-07 15:00 -0700
Message-ID<khb2ui$drs$1@n102.xanadu-bbs.net>
In reply to#8569
On 03/07/2013 08:49 AM, richard wrote:
> I have been searching the web for an answer but can't really find what I
> want to know.
>
> How do I retrieve the values from an array once the random number has been
> generated?
> In BASIC, one would simply say: show$=top$(1960,1).
> In PHP though, it seems you have to go through a miriad of loops just to
> find out if the value exists.
>
> So how is this done properly?
>
>
> <?php
>
> anum=rand(1,40);
> $num=anum
> $number="0" . $num;
> if ($num<10) {$number="0" . $number;}

Check your typing for '$' designating variables. This is
also important when writing BASIC code.    anum  -> $anum

Check your typing for semi-colons. This is
also important when writing BASIC code.    $num=anum  -> $num=$anum;

Check 'type'-ing to see that you are not asking to concatenate numeric
variables onto character strings. Leading zero suppression is leading
zero suppression, regardless how many zeroes you put in front.

Alastair

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web