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

后端 未结 9 1618
一个人的身影
一个人的身影 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:48

    This will map the array to a new array that utilizes the null ternary operator to either include an original value of the array, or an empty string if that value is null.

    $array = array_map(function($v){
        return $v ?: '';
    },$array);
    

提交回复
热议问题