I have an array coming in with sub arrays like this
Array
(
[0] => Array
(
[customers] => Array
(
[id] =>
)
[Products] => Array
(
[id] =>
)
[Models] => Array
(
[id] => 151
[SubModels] => Array
(
[ol] =>
)
[Noice] =>
)
)
I want to make a switch statement on the array
so something like this
switch($array){
case Products:
case customers:
case Models:
}
how would I do that. Thanks
Yes, you can pass an array to a switch.
In C, you cannot use arrays in switch (and expressions for case ). Also, the type passed to switch() and types specified in each case must match.
Switch case statement evaluates a given expression and based on the evaluated value(matching a certain condition), it executes the statements associated with it. Basically, it is used to perform different actions based on different conditions(cases).
since $array holds an array within it, it looks like you'll actually want to look at the keys of the array indexed at $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 ;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With