How to convert php array null to empty string: First create a PHP sample file; then use the "function null2none(&$arr) {...}" method to convert the null value to an empty string. .
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
How to convert a null array in php to empty? PHP null value to empty string method
/* * null值转为空字符串 @param array $arr */ function null2none(&$arr) { foreach ( $arr as $key => $val ) { if (is_null ( $val )) { $arr [$key] = ''; } if (is_array($arr[$key])) { null2none($arr[$key]); } } }
Related introduction:
is_array - Check whether the variable is an array
is_array ( mixed $var ) : bool
If var is an array, return true, otherwise return false.
is_null() function is used to detect whether a variable is NULL.
bool is_null ( mixed $var )
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert null array to empty in php. For more information, please follow other related articles on the PHP Chinese website!