I have result array and each array index represents combination of various objects (result is from doctrine query).
I want to combine these value to same indexes like you can see in example => Array [0] has 2 object values '0' and name so i want to combine these results to new array in 0 index and so on. So I can perform further processing on new result.
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)
I tried some code but real problem, I am facing is that it's not removing or unset-ing 0 index and showing offset '0' is undefined
code
$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);