Rumah >pembangunan bahagian belakang >tutorial php >返回给定索引的值
请问下,PHP是否存在这样的数组函数
已知数组
$a['a']=>'apple',$a['b']=>'banana,$a['p']=>'pear'
已知某个数组
$key = array('a','b','p');
获得对应数组$a的值,并得到数组如下
$val = array('apple','banana','pear');
$a = array('a' => 'apple', 'b' => 'banana', 'p' => 'pear');$key = array('a','b','p');foreach($key as $k) $val[] = $a[$k];print_r($val);
Array( [0] => apple [1] => banana [2] => pear)
$a = array( 'a'=>'apple', 'b'=>'banana', 'p'=>'pear');$key = array('a','b','p');$val = array();foreach($key as $v){ array_push($val, $a[$v]);}print_r($val);
$a = array('a' => 'apple', 'b' => 'banana', 'p' => 'pear');$key = array('a','b','p');foreach($key as $k) $val[] = $a[$k];print_r($val);
Array( [0] => apple [1] => banana [2] => pear)
没有自带,你就自己写