Re: Help with Array

From: Date: Mon, 11 Dec 2000 10:20:25 +0000
Subject: Re: Help with Array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29658@lists.php.net to get a copy of this message
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

« previous php.general (#29658) next »