반응형
Example 1)
Remove empty string elements
Elements made up of white space are not removed.
$arr = array("lemon", "", "", "\t\n", "orange");
$reduced_arr = array_filter($arr);
print_r($reduced_arr);
# Array
# (
# [0] => lemon
# [3] =>
#
# [4] => orange
# )
Example 2)
trim() removes whitespace from an empty string
$arr = array("lemon", "", "", "\t\n", "orange");
$reduced_arr = array_filter(array_map('trim',$arr));
print_r($reduced_arr);
# Array
# (
# [0] => lemon
# [4] => orange
# )
Example 3)
0 to organize into a base array.
$arr = array("lemon", "", "", "\t\n", "orange");
$reduced_arr = array_values(array_filter(array_map('trim',$arr)));
print_r($reduced_arr);
# Array
# (
# [0] => lemon
# [1] => orange
# )
반응형
'개발 꿀팁 > PHP' 카테고리의 다른 글
[PHP] Decimal point conversion, truncation, rounding, and rounding of numeric type variables (0) | 2018.01.19 |
---|---|
[PHP function] URL page image tag extraction (0) | 2018.01.16 |
[PHP] Back to previous page (0) | 2018.01.16 |
How to check data types in PHP, Gettype() (0) | 2018.01.16 |
[PHP] Removing duplicate values in arrays, Array_unique () (0) | 2018.01.16 |