I'm posting a form to a php script. Th开发者_如何学Goe form contains a dynamic number of fields named cardObjectX, where X is a counter. Example: cardObject1, cardObject2, and so on. I need to loop through all the cardObject fields in my php script, but because we don't know how many there will be for any given post, we can't hard-code the field names.
Is there a way I can grab an array of all the fields that start with cardObject?
this should help you get started:
foreach($_POST as $key=>$value) {
if(strpos($key,"cardObject")!==FALSE) {
//do something with this cardObject...
}
}
<input name="cardObject[1]" value="">
using this naming style in your inputs makes it possible to access these inputs as an array in php like this:
$_POST['cardObject'][1]
or loop throug every cardObject like this:
foreach($_POST['cardObject'] as $cardObject){
}
精彩评论