Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
How to add foreach inside switch php

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?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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;
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda