Home  >  Article  >  Backend Development  >  PHP gets the specified value from a multi-dimensional array in which column of the array?

PHP gets the specified value from a multi-dimensional array in which column of the array?

jacklove
jackloveOriginal
2018-05-22 14:09:361579browse

Many problems will be encountered in the process of obtaining arrays. This article will explain the relevant knowledge.

PHP gets the specified value of the multi-dimensional array in which column of the array

Mainly used:

array_column
array_search
<?php 
$user = array(   
    0 => array(   
        &#39;id&#39;    => 1,   
        &#39;name&#39;  => &#39;张三&#39;,   
        &#39;email&#39; => &#39;zhangsan@qq.com&#39;,   
    ),   
    1 => array(   
        &#39;id&#39;    => 3,   
        &#39;name&#39;  => &#39;李四&#39;,   
        &#39;email&#39; => &#39;lisi@qq.com&#39;,   
    ),   
    2 => array(   
        &#39;id&#39;    => 5,   
        &#39;name&#39;  => &#39;王五&#39;,   
        &#39;email&#39; => &#39;wangwu@qq.com&#39;,   
    ) 
);   
print_r(array_column($user,&#39;id&#39;)); 
?>
   
print_r会输出下列字段
Array
(
    [0] => 1
    [1] => 3
    [2] => 5
)

Then get the position of the corresponding value according to the array_search function

This This article explains the relevant knowledge of obtaining arrays. For more related knowledge, please pay attention to the PHP Chinese website.

Related recommendations:

php basic learning: PHP arrays and data structures

php basic learning: PHP file system

php basic learning: image processing

The above is the detailed content of PHP gets the specified value from a multi-dimensional array in which column of 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