Count Similar Array Keys

前端 未结 4 1589
花落未央
花落未央 2021-01-13 18:43

I have a POST request coming to one of my pages, here is a small segment:

[shipCountry] => United States
[status] => Accepted
[sku1] => test
[produc         


        
4条回答
  •  野的像风
    2021-01-13 19:09

    Well, if you know that every product will have a corresponding array key matching "productN", you could do this:

    $productKeyCount = count(preg_grep("/^product(\d)+$/",array_keys($_POST)));
    

    preg_grep() works well on arrays for that kind of thing.

提交回复
热议问题