PHP中的数组索引错误

时间:2017-03-08 17:45:35

标签: 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->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] => 
        )

)

1 个答案:

答案 0 :(得分:0)

请尝试这个

$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;

   }
}