0

So I'm using a foreach cycle like this:

foreach($cats_arr as $category) {
    $options_arr[$category->name] = false;
}

and when I var_dump($options_arr['Articles']) it comes out like this, so I assume that I'm building the array properly:

bool(false) string(1) "5"

Next, I need to assign that array as a value of a key-value pair in another array, and then it breaks. I'm doing it like this:

$admin_options = array(
"cats" => $options_arr
);

So I can access the array with $admin_options['cats'], but how to I access the array's keys that's assigned to the "cats" key?

EDIT: Here's what comes out when I var_dump($admin_options['cats'])

array(1) { [0]=> array(4) { ["Articles"]=> bool(false) ["Blog Posts"]=> bool(false) ["News"]=> bool(false) ["Uncategorized"]=> bool(false) } }

0

1 Answer 1

2

Your $options_arr contains multiple keys, so you will have to either specify the key or use a foreach loop:

// Echo first key
echo $admin_options['cats'][0]['Articles'];

// Or this for all the keys
foreach($admin_options['cats'] as $cat) {
    echo $cat['Articles'];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.