我如何获得使用foreach的多维数组值? [英] how can i get multidimensional array values using foreach?
问题描述
这里是我的代码
$ $ p $ $ $ $ $ $ $ $ $ $ $ $ array $ =v1,
input2=>v2),
数组(
input3=>v3,
input4 >v4)
);
类测试
{
函数testp()
{
global $ test;
foreach($ test as $ key => $ value)
{
echo $ value;
}
var_dump($ test);
echo is_array($ test);
}
}
$ obj = new testing();
$ obj-> testp();
我用is_array和 var_dump
来确认是否它的一个数组。
都罚款
,并忽略错误抑制忽略。现在我怎样才能从它的价值?
它是数组的数组, ($ test $ key => $ value)
$ b $ $ ($ value为$ k => $ v){
echo $ v;
$ p
$ b $ p $这会回应你的价值v1,v2,v3, v4一个接一个。
I want to use a multidimensional array in different functions.so i am making it as a global variable(array).i created a multidimensional array and made it as global to access in different function.now how can i get the values from it using foreach loop? here is my code
$test=array(
array(
"input1"=>"v1",
"input2"=>"v2"),
array(
"input3"=>"v3",
"input4"=>"v4")
);
class testing
{
function testp()
{
global $test;
foreach($test as $key => $value)
{
echo $value;
}
var_dump($test);
echo is_array($test);
}
}
$obj = new testing();
$obj->testp();
i used is_array and var_dump
to confirm whether its an array.
all are fine
and its shwoing Error suppression ignored. now how can i get the values from it?
It is array of arrays, what works for top order array, works further as well:
foreach($test as $key => $value)
{
foreach($value as $k => $v){
echo $v;
}
}
This will echo your values v1, v2, v3, v4 one after another.
这篇关于我如何获得使用foreach的多维数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!