Home > Backend Development > PHP Tutorial > 如何获取上一级数组的值

如何获取上一级数组的值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:40:00
Original
1583 people have browsed it

<code>        $ext_arr = array(
        'image' => array('gif', 'jpg', 'jpeg', 'png','tiff'),
        'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
        'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'txt', 'zip', 'rar', 'gz', 'bz2'),
    );
</code>
Copy after login
Copy after login

这是一个二维数组,如何根据二维中的值,获取一维中的值.
比如知道gif如何得到image. 或者根据提供的值mp3.能得到media.

回复内容:

<code>        $ext_arr = array(
        'image' => array('gif', 'jpg', 'jpeg', 'png','tiff'),
        'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
        'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'txt', 'zip', 'rar', 'gz', 'bz2'),
    );
</code>
Copy after login
Copy after login

这是一个二维数组,如何根据二维中的值,获取一维中的值.
比如知道gif如何得到image. 或者根据提供的值mp3.能得到media.

<code>echo in_array($extension,$ext_arr['image'])?'image':(in_array($extension,$ext_arr['media'])?'media':'file');
</code>
Copy after login

没办法,只能遍历上层数据逐个in_array检查。不然就再建个映射表。

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template