-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?

Thaillie
  • 1,362
  • 3
  • 17
  • 31
Abdus Sattar Bhuiyan
  • 3,016
  • 4
  • 38
  • 72
  • 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. – Sami Kuhmonen Nov 08 '15 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! – RiggsFolly Nov 08 '15 at 19:35
  • Possible duplicate of [Remove value from array In PHP](http://stackoverflow.com/questions/17252880/remove-value-from-array-in-php) – i am me Nov 08 '15 at 19:39
  • What type of variable is $menu, because with a post/get you just unset it when passing it? – i am me Nov 08 '15 at 19:41

1 Answers1

1

Did not test this, but this should work.

foreach ($menu as $index => $menu_item) {
    if ($menu_item['menu']['name'] == 'Reseller') {
        unset($menu[$index]);
    }
}
Thaillie
  • 1,362
  • 3
  • 17
  • 31