deepatpaul
Programmer
I have an array with n nested arrays in it. Example:
// Array's name is $detevent, with 2 nested arrays;
array(2) {
[0]=>
object(stdClass)(3) {
["id"]=>
string(1) "4"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
}
[1]=>
object(stdClass)(3) {
["id"]=>
string(2) "11"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
}
}
I'm performing a query on the ID field of each nested key's value to return a list of participants based on that ID. I want to have any results to be appended to that nested array, not the outside one that holds them. Here is what I have so far, but isn't appending (note that code snippet is encased in surrounding functional code):
for($i=0; $i < sizeof($detevent); $i++) {
$sql = "SELECT name FROM users
WHERE eventID = '{$detevent[$i]->id}'";
$database->setQuery($sql);
$participants = $database->loadObjectList();
if (!empty($participants)) {
array_merge($detevent[$i], $participants);
}
}
I want it so that each nested array has a new element at the end (I'll convert it to a CSV list before appending), like below
[0]=>
object(stdClass)(4) {
["id"]=>
string(1) "4"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
["participants"]=>
string(10) "Jane, John
// Array's name is $detevent, with 2 nested arrays;
array(2) {
[0]=>
object(stdClass)(3) {
["id"]=>
string(1) "4"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
}
[1]=>
object(stdClass)(3) {
["id"]=>
string(2) "11"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
}
}
I'm performing a query on the ID field of each nested key's value to return a list of participants based on that ID. I want to have any results to be appended to that nested array, not the outside one that holds them. Here is what I have so far, but isn't appending (note that code snippet is encased in surrounding functional code):
for($i=0; $i < sizeof($detevent); $i++) {
$sql = "SELECT name FROM users
WHERE eventID = '{$detevent[$i]->id}'";
$database->setQuery($sql);
$participants = $database->loadObjectList();
if (!empty($participants)) {
array_merge($detevent[$i], $participants);
}
}
I want it so that each nested array has a new element at the end (I'll convert it to a CSV list before appending), like below
[0]=>
object(stdClass)(4) {
["id"]=>
string(1) "4"
["sid"]=>
string(1) "0"
["catid"]=>
string(2) "67"
["participants"]=>
string(10) "Jane, John