我有一个人员数组,名称中带有一个键'n'。 'n'的值是一个数组,键'l'('last'的缩写)具有我想要获得的值,即姓。PHP:使用数组中值的字符串“地址”获取值
出于好奇的编程原因,我有姓氏的地址字符串。
我如何做到这一点?
我试过eval等等。
SORRY我不清楚!
我想要的是使用变量$ test来获取它。
E.g.是这样的:
$person[$test]
(?这显然是行不通的,但到底是什么)
$test
不会永远是 '两深'。例如。有时它会['a']['residential']['street']
<?php
$test = "['n']['l']";
echo "I've got a string with the array index ".$test. "\n";
$person = array("n"=>array('l'=>'SMITH'));
echo 'the array, $person, is this: '."\n";
print_r($person);
echo "What I want is ".$person['n']['l']. "\n";
?>
输出:
I've got a string with the array index ['n']['l'] the array, $person, is this: Array ( [n] => Array ( [l] => SMITH ) )
我要的是SMITH
我不完全知道它是你的问题。你表明你可以访问$ person ['n'] ['l'],但这似乎是你的问题。 –
你已经这么做了,怎么了? –
我并不清楚你的问题,但我绝对不希望的回声中显示一个数组的内容,但你必须使用的print_r()http://php.net/manual/en/function.print-r .PHP – JellyBelly