XMen XMen - 1 year ago 88
PHP Question

How to convert the null values to empty string in php array?

I want to convert this array that Array[4] should not give null it can give blank space (empty string).

Array (
[0] => 1
[1] => 4
[2] => 0
[3] => V
[4] =>
[5] => N

(The reason for the change, unrelated to the general question)

Fatal error: Uncaught exception
'PDOException' with message 'Database
error [23000]: Column 'message' cannot
be null, driver error code is 1048' in

Kel Kel
Answer Source

Then you should just loop through array elements, check each value for null and replace it with empty string. Something like that:

foreach ($array as $key => $value) {
    if (is_null($value)) {
         $array[$key] = "";

Also, you can implement checking function and use array_map() function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download