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 does php get where the value is in the array

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "php how to get the value in the array", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php how to get the value in the array which position" article.

Methods: 1, use "array_values (array)" to convert the specified array into an indexed array; 2, use "array_search (numeric, indexed array)" to search for values in the indexed array and return the corresponding index value (subscript); 3, because the index value is counted from 0, need to add 1 processing, syntax "index value + 1".

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

Php gets where the value is in the array

Implementation method:

Use array_values () to convert the specified array to an indexed array (mainly for associative arrays, but no change if it is already an indexed array).

$array=array ("id" = > 1, "name" = > "Li Hua", "age" = > 23, "1" = > 1, "id2" = > 52); var_dump ($array); $values=array_values ($array); var_dump ($values)

Use array_search () to search the indexed array for the specified value, and if successful, return the corresponding key name (index value or subscript).

(the key name of the indexed array is, of course, a numeric value, and each number corresponds to the position of an array element in the array)

$index=array_search (23 million values); echo $index

The key name of the indexed array is counted from 0, so add 1 to the key name.

Complete implementation code: check the position of the value 23 in the array

The above is about the content of this article on "how to get the value in the array by php". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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