Case statement

I have an array included in auxiliary arrays like

Array
(
    [0] => Array
        (
            [customers] => Array
                (
                    [id] => 

                )

            [Products] => Array
                (
                    [id] => 

                )

            [Models] => Array
                (
                    [id] => 151


                    [SubModels] => Array
                        (
                            [ol] => 
                        )

                    [Noice] => 
                )

        )

I want to make a switch statement in an array

so something like this

switch($array){

    case Products:

    case customers:

    case Models:
}

how would i do that. Thanks

+5
source share
1 answer

since $ array contains an array inside it, it looks like you really want to look at the array keys indexed in $ array [0]

foreach ($array[0] as $key => $value) {
    switch ($key) {
        case 'Products' :
            // do something
            break ;
        case 'customers' :
            // do something
            break ;
        case 'Models' :
            // do something
            break ;
     }
 }
+11
source

All Articles