-1

这是我的输出

Array
(
    [0] => Array
        (
            [count] => 3
            [TYPE] => 1
        )

    [1] => Array
        (
            [count] => 9
            [TYPE] => 2
        )

    [2] => Array
        (
            [count] => 0
            [TYPE] => 3
        )

    [3] => Array
        (
            [count] => 0
            [TYPE] => 4
        )

)

我现在得到了上面的数组,我像这样调用这个函数

$totalJobsCount = $model->GetStatus($data->id);

现在我想要 [0][count],[1][count],[2][count],[3][count] 的值,所以我这样写

$a = $totalJobsCount[0]['count'];

$a1 = $totalJobsCount[1]['count'];

$a2 = $totalJobsCount[2]['count'];

$a3 = $totalJobsCount[3]['count'];

但我得到了错误,未定义的偏移量 0 问题在哪里,请尽快帮助我提前谢谢

4

2 回答 2

0

我怀疑如果您提出更明确的答案并发布演示您的问题的可执行代码,您会得到更好的答案。

Array(...)您问题顶部的转储不是可执行代码。如果您将其替换为运行并生成该数据结构的代码,将会有所帮助。我在下面给出了一个例子。

仔细阅读有关数组的 PHP 文档。您是否遵循那里所说的内容?

究竟是哪一行导致了错误?您能否简化代码以不涉及函数调用,并且正是触发错误的最后一行?做这个练习可能会帮助你找到答案。

其他人已经指出,您在数组转储和数组查找表达式中都使用了不带引号的字符串。问题在于名称count指的是一个函数,所以在某些情况下 PHP 可以这样解释它。我怀疑您count在构建数组时在某处使用了未加引号的字符串,这就是问题所在。

下面的代码示例(我在codepad上测试过)演示了 PHP 中的多维数组在引用字符串时,甚至有时在不引用字符串时,其行为确实符合预期。

<? $totalJobsCount = Array
(Array(
            'count' => 3,
            'TYPE' => 1
        ),
 Array(
            count => 9,
            TYPE => 2
        ),
Array(
            'count' => 0,
            'TYPE' => 3
        ),
Array(
            'count' => 0,
            'TYPE' => 4
        )

); 
var_dump( $totalJobsCount );

print '$totalJobsCount[0][\'count\'] = '.$totalJobsCount[0]['count']."\n";
print '$totalJobsCount[1][count] = '.$totalJobsCount[1][count]."\n";
?>

上面的代码产生以下结果:

array(4) {
  [0]=>
  array(2) {
    ["count"]=>
    int(3)
    ["TYPE"]=>
    int(1)
  }
  [1]=>
  array(2) {
    ["count"]=>
    int(9)
    ["TYPE"]=>
    int(2)
  }
  [2]=>
  array(2) {
    ["count"]=>
    int(0)
    ["TYPE"]=>
    int(3)
  }
  [3]=>
  array(2) {
    ["count"]=>
    int(0)
    ["TYPE"]=>
    int(4)
  }
}
$totalJobsCount[0]['count'] = 3
$totalJobsCount[1][count] = 9
于 2012-04-10T06:04:10.790 回答
0
         $det = array( array( Title => "rose", 
                  Price => 1.25
                ),
           array( Title => "daisy", 
                  Price => 0.75
                ),
           array( Title => "orchid", 
                  Price => 1.15
                )
         );

         print_r($det);

          echo $det[0]['Title'];

$det[0]['Title'] 中的“玫瑰”

于 2012-04-10T05:38:59.557 回答