Re: Help with Array
| From: | Toby Butzon | Date: | Mon, 11 Dec 2000 10:28:55 +0000 |
| Subject: | Re: Help with Array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29661@lists.php.net to get a copy of this message | ||
Heh sorry about that... the line should read:
list ($key, $val) = each($person_ar);
Toby Butzon
[ criticism spurs improvement ]
----- Original Message -----
From: "RealGM Webmaster" <webmaster@realgm.com>
To: "Toby Butzon" <php-lists@imawebdesigner.com>
Sent: Monday, December 11, 2000 5:29 AM
Subject: Re: [PHP] Help with Array
:
: Thanks Toby,
:
: On the line:
:
: list ($key, $val) = each($my_array);
:
: It says Warning: Variable passed to each() is not an array or object in
: get_people.php on line 18
:
: Thanks,
: Michael
:
:
:
: Webmaster,
: Real General Manager, Inc.
: http://www.realgm.com
:
:
: ----- Original Message -----
: From: "Toby Butzon" <php-lists@imawebdesigner.com>
: To: "RealGM Webmaster" <webmaster@realgm.com>; "php-general"
: <php-general@lists.php.net>
: Sent: Monday, December 11, 2000 9:20 PM
: Subject: Re: [PHP] Help with Array
:
:
: > Hi Michael -
: >
: > Try this:
: >
: > /* get values from all 13 variables; store in an array */
: > for ($i = 1; $i <= 7; $i++) {
: > $person_ar[${"personA$i"}] = ${"personAnumber$i"};
: > }
: >
: > for ($i = 1; $i <= 6; $i++) {
: > $person_ar[${"personB$i"}] = ${"personBnumber$i"};
: > }
: >
: > /* sort it all out */
: > asort($person_ar);
: >
: > /* store sorted info into $person1, $person2, etc */
: > for ($i = 1; $i <= 13; $i++) {
: > reset($person_ar);
: > list ($key, $val) = each($my_array);
: > ${"person$i"} = $key;
: > }
: >
: > Let me know if you have problems...
: >
: > Toby Butzon
: > [ criticism spurs improvement ]
: >
: >
: > ----- Original Message -----
: > From: "RealGM Webmaster" <webmaster@realgm.com>
: > To: "php-general" <php-general@lists.php.net>
: > Sent: Monday, December 11, 2000 5:03 AM
: > Subject: [PHP] Help with Array
: >
: >
: > Hi,
: >
: > I have not gone into arrays in any great detail but I have a slight
: problem.
: >
: > I have two groups of people into memory variables, but the person's name
: and
: > a corresponding number. I need to "merge" these groups into an array,
: sort
: > the data by the number, then output into a different memory variable
(name
: > only).
: >
: > For instance, I have $personA1 and $personAnumber1 ... $personA7 and
: > $personAnumber7. PersonB only goes up to six, giving me a total of 13
: > people combined.
: >
: > I want to enter both of these details into an array, sort it by the
second
: > value (number), then output the first value only (name) to a new
variable
: > $person1, $person2, etc.
: >
: > I presume this would be simple but I get confused with arrays. Could
: > someone please help?
: >
: > Thanks,
: > Michael
: >
: >
: >
:
: