Re: replacing a null value using str_replace
| From: | Austin Marshall | Date: | Wed, 08 May 2002 02:03:34 +0000 |
| Subject: | Re: replacing a null value using str_replace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96511@lists.php.net to get a copy of this message | ||
Daniel Leighton wrote:
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.Are you dealing with strings or arrays. If arrays, it looks like what you did will work... but if you are really dealing with strings, then i think the function you are looking for is str_pad, not str_replace.... Hope that brings some insight.