Home > Backend Development > PHP Tutorial > PHP gets the specified value position in the array

PHP gets the specified value position in the array

不言
Release: 2023-03-24 10:26:02
Original
2617 people have browsed it

The content of this article is about PHP getting the specified value position in the array. It has a certain reference value. Now I share it with you. Friends in need can refer to it



Use php array_search function

<?php
    //定义一个数组
    $array = array(0 => &#39;a&#39;, 1 => &#39;b&#39;, 2 => &#39;c&#39;, 3 => &#39;d&#39;);
    //使用 array_search(&#39;要搜索的值&#39;,数组);
    $key = array_search(&#39;b&#39;, $array); // $key = 1;
    $key = array_search(&#39;a&#39;, $array);   // $key = 0;
?>
Copy after login

Related recommendations:

PHP Gets the number of the specified value in the multi-dimensional array. Column

PHP method to get last week, this week, last month, this month, this quarter, and last quarter time

The above is the detailed content of PHP gets the specified value position in the array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template