We introduce the operation of the array 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, the need for students can refer to.
Let's take a look at a number of ways that PHP can manipulate null values in an array
Implode (); This function can refer to the http://www.bKjia.c0m/phper/29/2dc95be9381b4bb1753083c09fda1a36.htm
Use implode () to output the array as a string to determine if the output is empty. It seems like a good way to start at first, but as with a little bit more than two-dimensional arrays. As an example:
The code is as follows |
Copy Code |
$arr = Array (array (), array (), array ()); $str = Implode (', ', $arr); if (empty ($STR)) echo "null"; else echo "non-null"; |
It is obvious that $arr is a two-dimensional array with three empty arrays, which should also be empty, but the output is indeed non-empty. Judgment failed.
III, COUNT (); Refer to Http://www.bKjia.c0m/w3school/php/func_array_count.htm
The code is as follows |
Copy Code |
$arr = Array ("", "", ""); echo count ($arr); |
Iv. In_array (', $arr)); Function usage 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 indicate that there are empty elements in the array and cannot prove that the array is empty. It's not obvious.
Five, empty (); Function usage refer to http://www.bKjia.c0m/so/php+empty ()
This Cpyeh thinks it's the same as the previous methods.
The code is as follows |
Copy Code |
$arr = Array ("", "", ""); if (empty ($arr)) echo "null"; else echo "non-null"; |
The result is still non-empty
Six, with strlen (), no content words as if the length of 1
In conjunction with the above example, we write a complete element that deletes an array of null values
|
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.html www.bkjia.com true http://www.bkjia.com/PHPjc/632230.html techarticle we introduce the operation of the array 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, the need for students can refer to. First, let's take a look at the Guan ...