首頁 >後端開發 >php教程 >关于数组取值的有关问题

关于数组取值的有关问题

WBOY
WBOY原創
2016-06-13 10:28:11903瀏覽

关于数组取值的问题!

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        ))


我要想取出对应的 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>
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.gifecho '$v ['.'savename'.']='.$v ['saveName'] .'<br>'   ;  }  }    ?><div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn