How to convert null array to empty in php

藏色散人
Release: 2023-03-10 09:22:01
Original
2452 people have browsed it

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]);
}
}
}
Copy after login

Related introduction:

  • is_array - Check whether the variable is an array

is_array ( mixed $var ) : bool
Copy after login

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 )
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!