Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Only process $_POST elements that begin with a certain string
- $_POST['city_1']
- $_POST['city_2']
- $_POST['city_3']
- $_POST['city_4']
- <input type="text" name="cities[city_1]">
- <input type="text" name="cities[city_2]">
- <input type="text" name="cities[city_3]">
- <input type="text" name="cities[city_4]">
- foreach($_POST['cities'] as $city)
- {
- echo $city;
- }
- $cities = preg_grep('/^city_d+$/', array_keys($_POST));
- foreach($cities as $city) {
- echo $_POST[$city];
- }
- foreach($_POST as $name=>$value) {
- if (strpos($value, 'city_') !== 0) continue;
- echo $value;
- }
- foreach($_POST as $key => $value)
- if(preg_match("/^city_d+$/", $key))
- ...
- function startsWith($haystack, $needle)
- {
- $length = strlen($needle);
- return (substr($haystack, 0, $length) === $needle);
- }
- foreach ($_POST as $k=>$v)
- {
- if (startsWith($k, 'city_')
- {
- // Process parameter here ...
- }
- }
- foreach($_POST as $key=>$value) {
- //filter based on $key
- }
Add Comment
Please, Sign In to add comment