Jump to content
MakeWebGames

need a little code effeciency help?


plintu

Recommended Posts

what would be a more effecient wat to write this?

if($ir['location']=='1'){die("You should not be here, you are under aged!");}

if($ir['location']=='2'){die("You should not be here, you are under aged!");}

if($ir['location']=='3'){die("You should not be here, you are under aged!");}

if($ir['location']=='4'){die("You should not be here, you are under aged!");}

if($ir['location']=='5'){die("You should not be here, you are under aged!");}

if($ir['location']=='6' && $ir['loved']=='3'){die("You got your lovin for today!");}

if($ir['location']=='7' && $ir['loved']=='5'){die("You got your lovin for today!");}

if($ir['location']=='8' && $ir['loved']=='7'){die("You got your lovin for today!");}

if($ir['location']=='9' && $ir['loved']=='10'){die("You got your lovin for today!");}

Link to comment
Share on other sites

Re: need a little code effeciency help?

 

$var = array('1','2','3','4','5','6','7','8','9');
$var2 = array('3','5','7','10');

if (in_array($ir['loved'],$var2) && in_array($ir['location'],$var)) { die("You got your lovin for today!"); }
else if (in_array($ir['location'],$var)) { die("You should not be here, you are under aged!"); }

 

Not tested but should work

Link to comment
Share on other sites

Re: need a little code effeciency help?

 

$var = array('1','2','3','4','5','6','7','8','9');
$var2 = array('3','5','7','10');

if (in_array($ir['location'],$var2) && in_array($ir['location'],$var)) { die("You got your lovin for today!"); }
else if (in_array($ir['location'],$var)) { die("You should not be here, you are under aged!"); }

 

Not tested but should work

that is close but it doesn't account for the && $ir['loved']=='3') part. I think I can get it from there, thank you!

Link to comment
Share on other sites

Re: need a little code effeciency help?

 

$locations = array(
   'allowed' => array(6,7,8,9),
   'notAllowed' => array(1,2,3,4,5),
   'loved' => array(3,5,7,10)
)
if(in_array($ir['location'],$locations['notAllowed'])) die("You should not be here, you are under aged!"); 
if(in_array($ir['loved'],$locations['loved'])) die("You allready had your lovin today!");
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...