In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to obtain the number of different elements of an array by php". In the operation of actual cases, many people will encounter such a dilemma, 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!
Get method: 1, use array_unique () function to remove repeated elements in the array, so that each element in the array has only one, syntax "array_unique ($arr)"; 2, use sizeof () to get the number of elements of the deduplicated array, syntax "sizeof (deduplicated array)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php gets the number of different elements in the array
Realize the idea:
To get the number of different elements in an array, you first need to remove the repeating elements in the array-- using array_unique ()
Then get the number of elements of the deduplicated array, that is, the length of the array-- using sizeof ()
Implementation code:
Description:
The array_unique () function removes duplicate values from the array and returns an array of results. When the values of several array elements are equal, only the first element is retained and the other elements are deleted. The key name in the returned array remains unchanged.
The sizeof () function can count the number of all elements in an array, or the number of attributes in an object.
That's all for "how to get the number of different 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.