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

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

    There is even better/shorter/simpler solution. Compilation of already given answers. For initial data

    [1, 4, "0", "V", null, false, true, 'true', "N"]
    

    with

    $result = array_map('strval', $arr);
    

    $result will be

    ['1', '4', '0', 'V', '', '', '1', 'true', 'N']
    

    This should work even in php4 :)

提交回复
热议问题