fugz
fugz

Reputation: 31

PHP Associative Arrays: Storing Keys and values

I am pretty new with associative arrays. Just trying to create a dynamic associative array.

Current Array -

stdClass Object
(
    [354] => Array
        (
        )

    [355] => Array
        (
        )

)

Trying to get desired output

stdClass Object
(
    [354] => Array
        (
            [activity_desc] = "description"
        )

    [355] => Array
        (
           [activity_desc] = "description"
        )

)

wrote an sql to check key (354, 355) and return description.

How to I store key and value under 344 & 355?

Current code:

foreach ($report as $key=>$value) 
{
    $where = 'item_id = ' . $key . '';		
	$query = $db->prepare('SELECT activity_desc FROM program WHERE '. $where);
	$query->execute();
	$test = $query->fetch(PDO::FETCH_OBJ);
}

this is my sql return query for 354. 355 will be roughly the same.

stdClass Object ( [activity_desc] => <p>Send Activity</p>

Thanks in advance

Fugz

Upvotes: 2

Views: 70

Answers (1)

fugz
fugz

Reputation: 31

wow it was that simple........

$report->$key = $test;

Upvotes: 1

Related Questions