PHP中的数组索引错误

PHP中的数组索引错误,php,arrays,Php,Arrays,我对使用PHP很陌生,并得到以下错误 PHP注意:第123行的ListPopulator.PHP中未定义的偏移量:1 当我进行一些搜索时,我发现这可能是由于数组索引,我只有[0]索引,但我不清楚如何修复它 我的代码如下: $testObj = new Test(); $this->build_one_all_tests = array(); $this->build_two_all_tests = array(); $build_one_tmp_tests = $testObj-&

我对使用PHP很陌生,并得到以下错误

PHP注意:第123行的ListPopulator.PHP中未定义的偏移量:1

当我进行一些搜索时,我发现这可能是由于数组索引,我只有
[0]
索引,但我不清楚如何修复它

我的代码如下:

$testObj = new Test();
$this->build_one_all_tests = array();
$this->build_two_all_tests = array();

$build_one_tmp_tests = $testObj->find_stream_build_multiple_platforms_failures_invalid_tests($this->product, $this->stream, $this->build_no , $this->platforms, $this->invalid_flag, $this->order_column, $this->desc);

foreach ($build_one_tmp_tests as $test) {   // line 123 where i got the error
        $test->crossed = false;

file_put_contents('/tmp/filename.txt', print_r($build_one_tmp_tests, true));
        $this->build_one_all_tests[$test->test_id.'_'.$test->platform_name] = $test;

}
数组输出如下所示

Array
(
    [0] => Test Object
        (
            [id] => 1646066
            [stream_id] => 606
            [build_id] => 9682
            [platform_id] => 7
            [test_id] => EditorsBrowserEditReference
            [idpath] => Editors/Browser/EditReference
            [result] => FAIL_WITH_CRASH
            [summary_path] => EditorsBrowserEditReference.html
            [log_path] => EditReference.txt
            [purelog_path] => EditReference.purelog
            [runtime] => 15
            [category] => Editors
            [started] => 2017-02-28 15:28:46
            [at] => 2017-02-28 15:29:01
            [host] => ies-esd-rhe5x64-07
            [display] => :277
            [owner] => aeshak
            [table_name] => test
            [stream_name] => waly_DRs_2016_1_Main
            [platform_name] => rhe5_64
            [build_name] => 2016.1_8
            [crossed] => 
        )

)
请试试这个

$testObj = new Test();
$this->build_one_all_testss = array();
$this->build_two_all_tests = array();
$build_one_tmp_tests = array();
$build_one_tmp_tests = $testObj->find_stream_build_multiple_platforms_failures_invalid_tests($this->product, $this->stream, $this->build_no , $this->platforms, $this->invalid_flag, $this->order_column, $this->desc);
if(!empty($build_one_tmp_tests))
 {
   foreach ($build_one_tmp_tests as $test)
    {   // line 123 where i got the error
        $test->crossed = false;
        file_put_contents('/tmp/filename.txt', print_r($build_one_tmp_tests, true));
        $this->build_one_all_tests[$test->test_id.'_'.$test->platform_name] = $test;

   }
}

看起来实际上有两个数组:第一个数组只有[0]字段,而在这个数组中,另一个数组有关联字段。您试图将第二个数组的偏移量用于第一个数组(只有0个字段),这就是为什么找不到偏移量1的原因-它根本不存在。哇!你给这个函数命名了吗
find\u stream\u build\u multiple\u platforms\u failures\u invalid\u tests()。我们能揭露/纠正真正的问题吗@您能确认错误线是环路、交叉线还是另一条线吗?我不是想侮辱你的智慧——有时候是一些小疏忽让我们落后了。它还可以提供long_命名函数来查看发生了什么。当一切正常时,我们需要把东西放在显微镜下。当我使用推荐的新条件if(!empty($build\u one\u tmp\u tests))时,我得到了相同的错误和相同的结果