-1

$menu contains:

Array
    (
        [0] => Array
            (
                [menu] => Array
                    (
                        [name] => Home
                        [controller] => frontends
                        [action] => index
                    )

            )

        [1] => Array
            (
                [menu] => Array
                    (
                        [name] => Feedback
                        [controller] => feedbacks
                        [action] => add
                    )

            )

        [2] => Array
            (
                [menu] => Array
                    (
                        [name] => Reseller
                        [controller] => resellers
                        [action] => login
                    )

            )

    )

I want to delete

[2] => Array
        (
            [menu] => Array
                (
                    [name] => Reseller
                    [controller] => resellers
                    [action] => login
                )

        )

unset($menu[2])

Works fine. But I am not sure that this menu always under 2 index. So I want to delete this item when $menu[$i][menu][name] == 'Reseller'. Anyone able to help?

4
  • If only there was a way to go through the array, check if a condition is true and use that index to remove items. Hint. Commented Nov 8, 2015 at 19:33
  • @SamiKuhmonen Wait, I think thare is a way to go through the array, check if a condition is true and use that index to remove items. Now what is it Ermmmm. Forsomethingorother! Commented Nov 8, 2015 at 19:35
  • Possible duplicate of Remove value from array In PHP Commented Nov 8, 2015 at 19:39
  • What type of variable is $menu, because with a post/get you just unset it when passing it? Commented Nov 8, 2015 at 19:41

1 Answer 1

1

Did not test this, but this should work.

foreach ($menu as $index => $menu_item) {
    if ($menu_item['menu']['name'] == 'Reseller') {
        unset($menu[$index]);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.