Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove null values from php Array

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to remove null values from php array". The explanation in this article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to remove null values from php array".

Method: 1, loop through the array, syntax "foreach ($arr as $k = > $v) {}"; 2, loop body, use "= =" to determine whether the element value is null, if so, delete the element with unset (), syntax "if ($v==null) {unset ($arr [$k]);}".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The method of getting rid of null value in php array

Implementation method:

Iterate through the array using the foreach statement

In the body of the loop, determine whether the array element is null, and if so, delete the element with unset ()

The unset () function destroys the given variable, unset ($arr [$key]).

Implementation example:

Expand knowledge:

The foreach statement traverses an array independent of the array subscript and can be used for discontiguous indexed arrays and associative arrays with strings as subscript.

Each time the foreach statement loops, the pointer inside the array moves forward so that the next array element is obtained in the next loop until it traverses to the end of the array, stops traversing and exits the loop.

There are two syntax formats for foreach statements:

Syntax format 1:

Foreach ($array as $value) {statement block;}

Iterate through the given $array array, assigning the value of the current array to $value in each loop.

Syntax format 2:

Foreach ($array as $key = > $value) {statement block;}

Iterate through the given $array array, assigning the value of the current array to $value and the key name to $key in each loop.

Thank you for reading, the above is the content of "how to remove the null value of the php array". After the study of this article, I believe you have a deeper understanding of how to remove the null value of the php array, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report