anyone know how to this?
switch ($page) {
foreach ($getcustpage as $k => $v) {
case $v:
print 'Variable $v tripped switch: '.$k.'<br>'.$v;
break;
}
case "result":
//result
break;
default:
//default
break;
}
I want to create a custom page from my settings. So the page will be available to access. anyone can help me?
I think you should break out your for loop outside of the switch. Now it is incorrect syntax. Try this:
foreach ($getcustpage as $k => $v) {
switch ($k) {
case $v:
print 'Variable $v tripped switch: '.$k.'<br>'.$v;
break;
case "result":
//result
break;
default:
//default
break;
}
}
I found the solution.
First i create normal switch like this
switch ($page) {
case "result":
//result
break;
default:
//default
break;
}
Then i need to add a logic in default switch
if (in_array($page, $getcustpage)) {
foreach ($getcustpage as $k => $v) {
print 'Variable $v tripped switch: '.$k.'<br>'.$v;
}
}else{
print $page;
}
Thanks for help.