Hello.
I have a form with multiple inputs. Transmitted by GET. I need to get the values ​​only pos1, pos4, pos15. (This is an example. In fact, they can be any number, under different numbers.) Or, one can say, output them into a separate array. Maybe something like this to do: $_GET['pos[0-9]{1,}'] ? But that doesn't work. Thanks for the help.

 <input name="in_comment" value=""> Комментарий<br> <input name="in_payer" value=""> Плательщик<br> Услуга <input name="pos1"> Сумма <input name="sum_pos1"><br> Услуга <input name="pos4"> Сумма <input name="sum_pos2"><br> Услуга <input name="pos15"> Сумма <input name="sum_pos2"><br> 

    2 answers 2

    @vitaan , why not group the elements in the form itself?

     <input name="in_comment" value=""> Комментарий<br> <input name="in_payer" value=""> Плательщик<br> Услуга <input name="pos[1]" value="a"> Сумма <input name="sum_pos[1]" value="1"><br> Услуга <input name="pos[4]" value="b"> Сумма <input name="sum_pos[2]" value="2"><br> <!-- Обратите внимание, у вас sum_pos2 в этом месте перезапишет предыдущее значение --> Услуга <input name="pos[15]" value="c"> Сумма <input name="sum_pos[2]" value="3"><br> 

    The array will be something like this:

     Array ( [in_comment] => "" [in_payer] => "" [pos] => Array ( [1] => "a" [4] => "b" [15] => "c" ) [sum_pos] => Array ( [1] => 1 [2] => 3 ) ) 
    • Cool! Human THANKS! What you need. And sum_pos2, yes, when I laid out, I apparently forgot to fix it. Thank you - REBOST
    • @vitaan, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - knes

    Crutch1:

     function reget($regexp){ $out = ''; foreach($_GET as $k=>$v){ if(preg_match($regexp,$k)){ $out[] = $v; } } return $out; } $arr_of_values = reget('pos[0-9]{1,}'); 

    Crutch2:

    Call them not pos1, pos2, but all the same: pos []. Before shipping, disable the unnecessary.

    Probably there is no non-sting method.

    PS

    instead of {1,} it is better to write +

    • Thanks, I will try. - REBOST