Adding columns to existing php arrays
Since you changed the code snippet in your question, try this instead now (updated version):
while(...) {
$row->cls = ...;
$row->parentID = ...;
$output[] = $row;
}
Loop through the array by reference and add what you want after the while loop:
foreach( $output as &$row) {
$row->cls = 0;
$row->parentID = 1;
}
You can also do this within the while loop:
while($row = $result->fetch_object()) {
$row->cls = 0;
$row->parentID = 1;
$output[] = $row;
}
$myArray=array_merge($myArray,$myAddArray);
https://www.php.net/manual/en/function.array-merge.php
or use array_push()
apply it in the foreach/while loop for each row.