0

我的阵列有问题。

$mini_one = array(
    "in" => "#pp1",
    "ot" => "the-r1",
    "fn" => "the_r1()",
    "js" => "$('the-r1').val($('#pp1').val());",
    "ep" => "not tested"
);

$mini_two = array(
    "in" => "#pp1",
    "ot" => "the-r1",
    "fn" => "the_r1()",
    "js" => "$('the-r1').val($('#pp1').val());",
    "ep" => "not tested"
);
//these are different but i just c/p it to show more than one array 
//inside of $big_array

$big_array = array($mini_one,$mini_two);

但是当我用 is_array() 测试 big_array 时它返回 false,它在我的 foreach 循环中也不起作用。

我想知道为什么它不是一个数组?,我怎样才能把它变成一个正确的数组?,现在,它被认为是什么类型的构造?

4

2 回答 2

0

代码是正确的

print_r($big_array);

if(is_array($big_array)) echo 'is array'; else echo 'not array';

将输出“是数组”

于 2012-06-08T16:49:56.020 回答
0

您需要粘贴确切的数组以便我们查看发生了什么。我尝试使用您上面的代码片段,它可以工作。您的 $big_array 将如下所示

Array
(
    [0] => Array
        (
            [in] => #pp1
            [ot] => the-r1
            [fn] => the_r1()
            [js] => $('the-r1').val($('#pp1').val());
            [ep] => not tested
        )

    [1] => Array
        (
            [in] => #pp1
            [ot] => the-r1
            [fn] => the_r1()
            [js] => $('the-r1').val($('#pp1').val());
            [ep] => not tested
        )

)

so its multidimensional to loop through it with foreach you need to do the following.
foreach($big_array as $k=>$v) {
foreach($v as $v1) {
echo $v1."<br>";
}
}
于 2012-06-08T16:56:50.960 回答