Answer the question
In order to leave comments, you need to log in
How many variables can be combined into one (for loop)?
There is a cycle
for ($I =0; $I<1000; $I++) {
isset($_GET['idoffers'.$I])?($_GET['idoffers'.$I]):'';
}
if(!empty$_GET['idoffers5'] ||....$_GET['idoffers1000'])) {
....
}
$test= $_GET['idoffers5']..$_GET['idoffers1000']
if(!empty($test)) {
....
}
Answer the question
In order to leave comments, you need to log in
what does single variable mean? read how the for loop works. Firstly, the for ($I =0; $I<1000; $I++) construct will return $i in the range from 0 to 999. Secondly, just check each variable for isset or empty and in case the condition is not met , go further through the loop thanks to the continue statement;
In reality it will look something like this
for ($i =0; $i<1000; $i++) {
if (empty($_GET['idoffers'.$i])) {
continue;
}
//ваша логика
}
<form action=2.php>
<input name="idoffers[]">
<input name="idoffers[]">
<input name="idoffers[]">
<input name="idoffers[]">
<input name="idoffers[]">
</form>
if(!empty($_GET['idoffers']))
{
foreach($_GET['idoffers'] as $key => $value)
{
print "$id = $value <br>";
}
}
There is a
for ($I =0; $I<1000; $I++) {
isset($_GET['idoffers'.$I])?($_GET['idoffers'.$I]):'';
}
After it we get idoffers1..idoffers1000
now I need to do a type check:
if(!empty($idoffers1.$idoffers1000)) {
....
}
$test= idoffers1..idoffers1000in general, some kind of masochism.
if(!empty($test)) {
....
}
You already have them in one, in $_GET
, which means:
But I would send these variables as nested $_GET['idoffers'][1], $_GET['idoffers'][2], etc. , then everything is simple and besides your idoffers in get there can be anything else, and you check only them.
Why do you need a cycle here at all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question