Home > Backend Development > PHP Tutorial > 关于数组取值的有关问题

关于数组取值的有关问题

WBOY
Release: 2016-06-13 13:27:14
Original
790 people have browsed it

关于数组取值的问题!

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
//已知数组
$info=array();
//输出
print_r($info);
//结果
Array
(
    [0] => Array
        (
            [name] => 8.gif
            [md5] => b68d88dbdfc9d0af2e0bbd85a4ccd28f
            [saveName] => 20120602080557_452.gif
            [size] => 1
            [type] => image/gif
            [originalHeight] => 39
            [originalWidth] => 31
        )

    [1] => Array
        (
            [name] => 9.gif
            [md5] => 4988f85ebebf82f56d70eeaf39a67016
            [saveName] => 20120602080557_776.gif
            [size] => 2
            [type] => image/gif
            [originalHeight] => 39
            [originalWidth] => 31
        )

)


Copy after login


我要想取出对应的 saveName 的值, 请问该如何下手

------解决方案--------------------
PHP code

foreach($info as $value){
foreach($value as $getValue){
echo $getValue['saveName'];
}

}
<br><font color="#e78608">------解决方案--------------------</font><br>foreach($info as $v)  $temp[]=$v['saveName'];<br>print_r($temp);
<br><font color="#e78608">------解决方案--------------------</font><br>看来name是类似于唯一字段了,想取出来和name对应的savename字段。如果这样的话,需要接收你给的name字段值,当你用post表单提交的吧。<br><br>二维数组。一个foreach判断就够了<br><br>
Copy after login
PHP code

$a=Array( Array (
            'name' => '8.gif',
            'md5' => 'b68d88dbdfc9d0af2e0bbd85a4ccd28f' ,
            'saveName' => '20120602080557_452.gif',
            'size' => 1       ,
            'type' => 'image/gif'   ,
            'originalHeight' => 39 ,
            'originalWidth' => 31
        ),
Array(
            'name' => '9.gif'      ,
            'md5' => '4988f85ebebf82f56d70eeaf39a67016',
            'saveName' => '20120602080557_776.gif'  ,
            'size' => 2    ,
            'type' => 'image/gif'  ,
            'originalHeight' => 39 ,
            'originalWidth' => 31 ,
        )

)   ;
foreach ($a as $k=>$v) {
if ($v['name']===$_POST['yourname']){//令$_POST['yourname']=‘8.gif’,将输出$v ['saveName']=20120602080557_452.gif
echo '$v ['.'savename'.']='.$v ['saveName'] .'<br>'   ;  }  }
    
?> <div class="clear">
                 
              
              
        
            </div>
Copy after login
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