Re: Looking up, deleting and inserting array values
| From: | Jochem Maas | Date: | Wed, 10 May 2006 07:27:36 +0000 |
| Subject: | Re: Looking up, deleting and inserting array values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235858@lists.php.net to get a copy of this message | ||
Jonas Rosling wrote:
Hi,
I'm trying to do something that I know works when you build an array like a
"map" with elements and values. One of the problems with this is that I only
get out the values from the array from the last row. And the other problem
is it looks like I can't delete desired values within the array. Is anyone
able to tell me if it's really possible? And if it is, how?
A snip of my code follows bellow:
($$row[3] contains single values that apear in the rows and are decleared
higher up on the page)
while($row=mysql_fetch_array($result)) {
// If var based named as value in $row[3]
if ($$row[3]) {
if (${$row[3]}) {
// i.e. help php to figure out how to exactly what you mean
// with curlie braces.
// the for ease of viewing make a reference:
$myArr =& ${$row[3]};
// Splits keys and values
foreach($$row[] AS $key => $value) {
foreach($myArr AS $key => $value) {
unset($myArr[$key]); // unset(${$row[3]}[$key]);// If $value is the same as $row[2] if ($value == $row[2]) { // Sum old value within the array with the new value $new_value = $value+$row[2];// Delete the old value from the array unset($$row[3][$key]);
// Insert the new value
array_push($$row[3], $new_value);
$myArr[] = $newValue;
}
}
}
}
Thanks in advance // Jonas
(Yes, I try to read the manual - but it's not allways good enough for me)