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

何が起こっているかを確認するには、正確な配列を貼り付ける必要があります。上記のコードスニペットを使用してみました。$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 に答える
0

コードは正しいです

print_r($big_array);

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

「配列です」を出力します

于 2012-06-08T16:49:56.020 に答える