PHP gets the column of the array where the value specified in a multi-dimensional array is

不言
Release: 2023-03-24 09:36:01
Original
2078 people have browsed it

This article mainly introduces PHP to get the specified value of the multi-dimensional array in which column of the array. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

PHP to get the multi-dimensional array The specified value is 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;));
?>
Copy after login

print_r will output the following fields

Array
(
[0] => 1
[1] => 3
[2] => 5

)

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

For detailed function introduction, you can view the manual or the corresponding article


Related recommendations:

7 ways for PHP to get file extensions

php Get some time to implement the method practice

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