I have the following code:
foreach ($result as $row) {
$categories[] = array('id' => $row['id'], 'name' => $row['name']);
if($categories['id'] = $selectedcategory ){
$categories['selected'] = 'true';
}
This creates an array with all id and names from a query. And it's ok. Than it does a check against a specific value ($selectedcategory) and add a key 'selected' with value 'true'.
When I do print_r to $categories I get:
Array ( [0] => Array ( [id] => 1 [name] => Expertise ) [selected] => true [1] => Array ( [id] => 2 [name] => Tools ) [2] => Array ( [id] => 3 [name] => On the go ) [3] => Array ( [id] => 4 [name] => Lab ) [4] => Array ( [id] => 5 [name] => Know How ) )
It puts the selected key to the right id value (1) but it is placed out of the Array 0 brackets.
What am I doing wrong?