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

PHP gets the specified value position in the array

不言
不言Original
2018-04-18 14:02:132645browse

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;
?>

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!

Statement:
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