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

后端 未结 9 1598
一个人的身影
一个人的身影 2020-12-16 13:31

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] =>         


        
9条回答
  •  时光取名叫无心
    2020-12-16 13:55

    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.

提交回复
热议问题