Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
Obtenga el valor de una matriz $_POST específica
name="qty<?php echo $key?>" foreach ($_POST as $items => $value) { // check qty >1??? echo $key, ' => ', $value, '<br />'; }

¿Cómo muestro solo elementos cuyos valores son [cantidad1]=>valor,[cantidad2]=>valor... >0?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

¿Por qué no agrega un cheque en su ciclo y luego obtiene una salida filtrada como esta?

si su solicitud POST no es una matriz multidimensional , use esto:

 $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);

Si su solicitud POST es una matriz multidimensional , use esto:

 $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);

¡Espero que eso ayude!

over 4 years ago · Santiago Trujillo Denunciar

0

Simplemente use la combinación de array_filter y 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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda