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

289
Visualizações
Get value of specific $_POST array
name="qty<?php echo $key?>"



foreach ($_POST as $items => $value)
{
  // check qty >1???
echo $key, ' => ', $value, '<br />';
}

How do I show only items which their values of [qty1]=>value,[qty2]=>value... >0 ?

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

0

Why don't you add a check in your loop and then get a filtered output like this:

if your POST request is not a multidimensional array then use this:

$output = array_filter($_POST, function ($value, $key) {
        // check your keys start with 'qty' and its value is greater than one
        return strpos($key, 'qty') === 0 && $value > 1; 
    }, ARRAY_FILTER_USE_BOTH);

// display final output
print_r($output);

If your POST request is a multidimensional array then use this:

$output = array(); // declare a blank array to store filtered output

foreach($_POST as $row)
    {
    if (is_array($row))
        {

        // this code is because qty is dynamic and we need to check it for all.

        foreach($row as $key => $value)
            {
            if ("qty" == substr($key, 0, 3) && $value > 0)
                {
                $output[] = $row;
                }
            }
        }
    }

// display final array.

print_r($output);

Hope that will help!

over 4 years ago · Santiago Trujillo Relatório

0

Just use combination of array_filter and print_r.

$_POST = [
   'notme' => 12,
   'qty1' => 1,
   'qty2' => 20,
   'qty3' => -1,
   'qty4' => 0,
   'qty5' => 30
];

print_r(
    array_filter($_POST, function ($value, $key) {
        // check key starts with 'qty' and its value is greater than one
        return strpos($key, 'qty') === 0 && $value > 1; 
    }, ARRAY_FILTER_USE_BOTH)
);

// Array ( [qty2] => 20 [qty5] => 30 )
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