Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Loops in PHP

Hi,

I have a bit of PHP at the top of my checking page, I need it to run through ten variables (var[1] thru var[10]) and make sure they all are more than "" they contain something, if they all do I need to it to then convert all those var[1] etc to their real values like
$username=var[1] etc and then jump to another URL to process, if one of these variables is still empty I need it to continue loading the page, how do I go about this ?
0
MirageSF
Asked:
MirageSF
1 Solution
 
VGRCommented:
ok, first you need an array holding the "real names" of your variables, like this :
$realnames=array();
$realnames[0]="username";
[...]
$realnames[9]="lastname";

then you code is as follows :
<?
$nbv=0; // counter of empty values
for ($i=0;$i<10;$i++) { // explore variables set to validate
  if ($var[$i]=="") $nbv++; else ${$realnames[$i]}=$var[$i];
} // for explore
if ($nbv==0) { // set true names and relocate somewhereelse
} // else nothing, continue to "load the page"
?>
0
 
a1programmerCommented:

<?
// first, check to see that all variables exist

for ($x = 0; $x < 10; $x++)
    if ($var[$x] =="")      // or !isset($var[$x])
           exit;  // if any of the values are empty, page stops processing.
?>


// if you made it here, you have all your values...

$username = $var[0];
$lastname = $var[1];
$email    = $var[2];
...
$age      = $var[9];
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now