The problem is that I am in a loop, so $output[0] would work only with the first element...
So the solution I am using right now (and which works), is that I don't let PHP automatically increment the keys, and provide it with a key I increment myself:
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$output[$i] = array( 'id' => $row['id'],
'name' => $row['name'] );
$output[$i]['contract_id'] = $details_contract['id'];
$output[$i]['contract_name'] = $details_contract['name'];
$i++;
}
Don't ask why I didn't simply add the fields in when I first create the variable, because I stripped some of the code...
So this works, but I'd find it simpler to let PHP auto-increment the keys, and use something like
$output[$PHP_LAST_INCREMENT]['contract_id'] = ...