In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to find the array subscript of php". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "php how to find array subscript"!
Two methods: 1. Using array_keys, the syntax "array_keys (array, search value, false | true)" returns an array containing subscript. 2. Traverse the array and store the subscript in an empty array with the syntax "foreach (array as $k = > $v) {$r [] = $k;}".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The array array is an ordered set of variables, where each value is called an element. Each element is distinguished by a special identifier called a key (also known as a subscript).
So how to find the array subscript in php? Here are two methods.
Method 1: directly use the built-in function array_keys ()
The array_key () function can get some or all of the key names (subscript) in the array. The syntax format of this function is as follows:
Array_keys ($array,$search_value,$strict)
The parameters are described as follows:
$array: required parameter, which is the array to be operated
$search_value: optional parameter. If the argument is empty, the function will return all the key names in the array. If this parameter is specified, the function will only return the key name with the value of $search_value
$strict: optional parameter to determine whether strict mode is used when searching. $strict defaults to false, that is, non-strict mode. When searching, only types are compared, not types. If $strict is set to true, strict mode, value and type are compared at the same time when searching, which is equivalent to = =.
The array_key () function returns the resulting array key name as an array.
Example 1: all key names
Example 2: specify the key name of the value
Method 2: use the foreach statement to traverse the array and store the key name in an empty array
At this point, I believe you have a deeper understanding of "php how to find the array subscript", might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.