Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数组的空元素设置为NULL_Php - Fatal编程技术网

Php 将数组的空元素设置为NULL

Php 将数组的空元素设置为NULL,php,Php,我得到了一个包含很多元素的数组 这些元素可能是$data[0]=” 如果是这种情况,我想将数据设置为NULL,但是由于这将是经常进行的,我想知道是否有一种方法可以在默认情况下使NULL而不是循环查找”给出一个示例或数组集;如果一个值是0或“0”或[](空数组),该怎么办?考虑在构建一个ARAYIT时处理空值可以用一组函数来实现,但是对于这样简单的任务来说,它将过于复杂。常规的foreach循环就足够了 <?php $array = [ '',

我得到了一个包含很多元素的数组

这些元素可能是
$data[0]=”


如果是这种情况,我想将数据设置为
NULL
,但是由于这将是经常进行的,我想知道是否有一种方法可以在默认情况下使
NULL
而不是循环查找
给出一个示例或数组集;如果一个值是
0
“0”
[]
(空数组),该怎么办?考虑在构建一个ARAYIT时处理空值可以用一组函数来实现,但是对于这样简单的任务来说,它将过于复杂。常规的
foreach
循环就足够了
    <?php

    $array = [
        '',
        '0',
        '1'
    ];
    $nullArray = array_fill(0, 3, null);
    $filter = array_filter($array);
    var_dump($filter + $nullArray);