Home >Backend Development >PHP Problem >How to convert null array to empty in php

How to convert null array to empty in php

藏色散人
藏色散人Original
2021-06-02 15:22:232557browse

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. .

How to convert null array to empty in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to set up php gb2312Next article:How to set up php gb2312