1
我有結果陣列,並且每個數組索引表示各種對象(結果是從教義查詢)的組合。
我想這些值組合以相同的索引一樣可以例如在看到=>數組[0]有2個對象值「0」和名字所以我要這些結果來新陣列中0的索引等結合。所以我可以對新結果進行進一步處理。變換對象到陣列鍵表示後未定義偏移
array (size=4)
0 =>
object(stdClass)[568]
public '0' =>
object(stdClass)[552]
public 'id' => int 16
public 'userId' => int 250
public 'content' => string '<script>alert('Alert');</script>
adad adad adad
### Heading' (length=61)
public 'name' => string 'biling' (length=13)
1 =>
object(stdClass)[556]
public '0' =>
object(stdClass)[554]
public 'id' => int 15
public 'userId' => int 250
public 'content' => string '<script>alert('Alert');</script>
adad
### Heading' (length=51)
public 'name' => string 'biling' (length=13)
我嘗試了一些代碼,但真正的問題,我面對的是,它不刪除或取消-ING 0指數,顯示偏移「0」是未定義
代碼
$results = 'Object Result which i shown';
$data = array();
foreach ($results as $key => $item) {
$resultsCopyArray = array_diff_key((array)$item, [0]);
//this function must escape 0 index from $item and just add name to $resultsCopyArray but it's now working like it should be
var_dump(array_keys($resultsCopyArray));
// -> showing 0, name
// var_dump($resultsCopyArray[0]); -> showing error
// I also tried to unset this value but noting
$data[] = (array)$item->{'0'} + $resultsCopyArray;
}
var_dump($data);
感謝澄清:)也因爲相同unset()的原因不起作用? –