0

I can’t seem to get the result I need. Here is the array as it is provided by the sql query:

Array (
 [0] => Array ( 
     [id] => 7
     [description] => Accepted )
 [1] => Array ( 
     [id] => 8
     [description] => Declined )
 [2] => Array (
     [id] => 11 
     [description] => Deferred ) 
     )

Here is the format for how I need to have it foreach of the objects listed above:

['7'][‘7’] = “Accepted”;
['7'][‘8’] = “Declined ”;
['7'][‘11’] = “Deferred”;

...where the first array[‘7’] is an added value and needed for each object.

Seems easy enough, but the foreach statements I created return an error “cannot use scalar value as an array”</p>

4

1 回答 1

2
$rows = /*Your Data above*/
$data = array('7'=>array());
foreach($rows as $row)
    $data['7'][$row['id']] = $row['description'];

$jsonData = json_encode($data);

可能会完成

于 2012-09-18T22:23:06.387 回答