$arr= array(array(),array(),array());
代码如下 |
复制代码 |
$arr= array("","","");
echo count($arr);
|
$str = implode(',',$arr);
if(empty($str)) echo "empty";
代码如下 |
复制代码 |
$arr= array("d","s","");
echo in_array('', $arr); |
else echo "not empty";
代码如下 |
复制代码 |
$arr= array("","","");
if(empty($arr)) echo "空";
else echo "非空";
|
Obviously $arr is a two-dimensional array containing three empty arrays, which should be considered empty, but the output is indeed non-empty. Judgment failed.
3. count(); Please refer to http://www.bKjia.c0m/w3school/php/func_array_count.htm
The code is as follows
|
Copy code
|
代码如下 |
复制代码 |
function array_remove_key($array, $keys)
{
$num = count($keys);
$num_last = $num - 1;
$this_array_0 = &$array;
$last_key = $keys[$num_last];
for ($i = 0; $i < $num_last; $i++)
{
$this_key = $keys[$i];
$this_var_name = 'this_array_' . $i;
$next_var_name = 'this_array_' . ($i + 1);
if (!array_key_exists($this_key, $$this_var_name)) {
break;
}
$$next_var_name = &${$this_var_name}[$this_key];
}
unset(${$next_var_name}[$last_key]);
return $array;
}
|
$arr= array("","",""); |
echo count($arr);
4. in_array('', $arr)); For function usage, please refer to http://www.bKjia.c0m/phper/24/c5b81a8af14b1c0928eea343f59b454a.htm
The code is as follows
|
Copy code
|
$arr= array("d"," s","");
echo in_array('', $arr);
This can only show that there are empty elements in the array, but cannot prove that the array is empty. Obviously not.
5. empty(); For function usage, please refer to http://www.bKjia.c0m/so/php+empty()
This cpyeh feels similar to the previous methods
The code is as follows
|
Copy code
|
$arr= array("","","");
if(empty($arr)) echo "empty";
else echo "not empty";
The result is still non-empty
6. Use strlen(). If there is no content, the length seems to be 1
Combined with the above example, we write a complete deletion of empty elements in the array
The code is as follows
|
Copy code
|
function array_remove_key($array, $keys)
{
$num = count($keys);
$num_last = $num - 1;
$this_array_0 = &$array;
$last_key = $keys[$num_last];
for ($i = 0; $i < $num_last; $i++)
{
$this_key = $keys[$i];
$this_var_name = 'this_array_' . $i;
$next_var_name = 'this_array_' . ($i + 1);
if (!array_key_exists($this_key, $$this_var_name)) {
break;
}
$$next_var_name = &${$this_var_name}[$this_key];
}
unset(${$next_var_name}[$last_key]);
return $array;
}
http://www.bkjia.com/PHPjc/632230.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632230.htmlTechArticleWe introduce the operation of arrays in php, delete the specified value in the array or determine whether there is a value in the array or clear the empty Value operation, students in need can refer to it. First let’s take a look at...
|
|
|
|