RE: [PHP] Unexpected values in an associative array
- From: instructicc@xxxxxxxxxxx ("Instruct ICC")
- Date: Tue, 31 Jul 2007 09:06:30 -0700
From: Ken Tozier <kentozier@xxxxxxxxxxx>
Hi
I think this is probably just a misunderstanding on my part, but I'm creating associative arrays with string keys from MySQL query results and when I put a value in the array, I get the expected key association along with an index key that has a different value.
And here's some sample output
array(6) {
["task_id"]=>
int(22)
[0]=>
string(2) "22"
["container_id"]=>
int(3784)
[1]=>
string(4) "3784"
["name"]=>
string(12) "108-6972.XTG"
[2]=>
string(24) "3130382D363937322E585447"
}
Why is that? Is there any way to fix this without coercing the same value twice? Once for the key accessor and once for the index accessor?
Thanks In advance
Ken
What is $coersions or $inQuery['coersions']? Maybe a var_dump or a print_r on that for the list?
What is $value and what is this supposed to do:
case 'integer':
$value += 0;
break;
case 'float':
$value += 0.0;
If $value is a string, you should quote your 0 and 0.0. What add 0 or 0.0 to an int or float respectively?
Do a print_r on $row before your foreach ($row as $key => $value) and echo your $key and $value as the first line in after that for loop. Then echo $coersions[$key]. Does $coersions[$key] have what you want for switch ($coersions[$key]) at this point? I assume you expect $coersions to contain datatypes, but does it?
Perhaps "start at the end" considering the structure of the output array you want, then consider how to populate it to have that structure.
What's the extra "[]" about in $rows[$groupKey][] = $fields;
Maybe that's where your duplicates are coming from although I don't see duplicates in your output.
_________________________________________________________________
http://liveearth.msn.com
.
- Follow-Ups:
- Re: [PHP] Unexpected values in an associative array
- From: Ken Tozier
- Re: [PHP] Unexpected values in an associative array
- References:
- Unexpected values in an associative array
- From: Ken Tozier
- Unexpected values in an associative array
- Prev by Date: Re: [PHP] if inside an echo.
- Next by Date: Re: [PHP] Authentication
- Previous by thread: Re: [PHP] Unexpected values in an associative array
- Next by thread: Re: [PHP] Unexpected values in an associative array
- Index(es):
Relevant Pages
|