Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending an array to an existing nested array

Status
Not open for further replies.

deepatpaul

Programmer
Jul 7, 2004
57
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top