Get value of specific $_POST array

前端 未结 2 1117
栀梦
栀梦 2021-01-29 09:47
name=\"qty\"



foreach ($_POST as $items => $value)
{
  // check qty >1???
echo $key, \' => \', $value, \'
\'; }
2条回答
  •  旧巷少年郎
    2021-01-29 10:35

    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 )
    

提交回复
热议问题