RE: Unexpected values in an associative array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux