以下數組具有重複和非重複數據。PHP未定義財產通知
$arr = array();
//non repeating data
$data = new StdClass();
$data->name = $name;
$data->url = $url;
$arr[] = $data;
//repeating data
foreach($records as $rec) {
$data = new StdClass();
$data->text = $rec->text;
$data->time = $rec->time;
$arr[] = $data;
}
現在我要檢索的陣列的數據,所以我想這樣的:
echo $arr[0]->name;
echo $arr[0]->url;
foreach ($arr as $rec) {
echo $rec->text;
echo $rec->time;
}
我得到通知如下:
Notice: Undefined property: stdClass::$text in xx.php on line 48
線#48 echo $rec->text;
我如何解決這個通知而不是隱藏它?
請出示$錄音功的第一指標開始打印值ds? –