Daniel Leighton
2002-05-08 01:15:48 UTC
Hi,
I was attempting to replace null values in an array with 0 using str_replace, but was unsuccessful. The values in question were coming from a MySQL query which returned an empty set. Here is what I tried:
$result = str_replace('', 0, $result);
Here is what I ended up doing instead (which did work):
//set all null values to 0
while(list($key, $value) = each($result))
if(!$result[$key]) $result[$key] = 0;
Is there any way to do this str_replace? Is there another way I should be doing this? Any insights are greatly appreciated.
I was attempting to replace null values in an array with 0 using str_replace, but was unsuccessful. The values in question were coming from a MySQL query which returned an empty set. Here is what I tried:
$result = str_replace('', 0, $result);
Here is what I ended up doing instead (which did work):
//set all null values to 0
while(list($key, $value) = each($result))
if(!$result[$key]) $result[$key] = 0;
Is there any way to do this str_replace? Is there another way I should be doing this? Any insights are greatly appreciated.
--
Daniel Leighton
Chief Technology Officer
Webolution
http://www.webolution.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Daniel Leighton
Chief Technology Officer
Webolution
http://www.webolution.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php