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 php gets several elements in an array

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

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to get several elements in the array by php". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php to get several elements in the array method: 1, the use of count () function, you can count the number of all elements in the array, the syntax "count (array,mode)"; 2, the use of sizeof () function, you can calculate the number of elements in the array, syntax "sizeof (array,mode)".

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

It's easy to count the elements of an array in PHP. PHP provides us with two functions, the count () and sizeof () functions.

In fact, the sizeof () function is an alias for the count () function, that is, the function and usage of the sizeof () function is exactly the same as the count () function.

Let's introduce the count () function to understand these two functions.

The count () function can count the number of all elements in an array, or the number of attributes in an object. The syntax format is as follows:

Count (array,mode)

The parameters are described as follows:

Array: an array or object to be counted

Mode: optional parameter, which can be omitted.

If you omit the mode parameter, or set it to COUNT_NORMAL or the zero count () function will not detect multidimensional arrays

If mode is set to COUNT_RECURSIVE or the 1 count () function will recursively count the number of elements in the array, it is especially useful for counting the number of elements in a multi-dimensional array.

Example 1: count the number of elements in an one-dimensional array

Example 2: count the number of elements in a two-dimensional array

That's all for "how to get a few elements in an array by php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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