在php中,有个多维数组$b=array();,有个字符串$a='[1][1]';有木有办法从$b中取出$a位置上的值?

WBOY
Release: 2016-06-23 13:02:40
Original
862 people have browsed it

换句话说就是能不能用$a表示出$b[1][1]的形式。


回复讨论(解决方案)

$a是不断变化的啊  还有可能是$a='[1][1][1]';有木有大神知道啊

不行吧 要拆分$a成数组,循环。可变变量的形式应该不行


$a = array(array(1, 2, 3));
$b = '[0][2]';
$c = '$a' . $b;
eval('$d=' . $c . ';');
echo $d;
?>


$a = array(array(1, 2, 3));
$b = '[0][2]';
$c = '$a' . $b;
eval('$d=' . $c . ';');
echo $d;
?>

虽然eval被禁止使用,但也只能用这样的方法了,感谢!

自己琢磨出来的

$b=array(array(1, 2, 3));
$a="[0][2]";
echo eval("return \$b$a;");
exit;
?>

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!