Jump to content
MakeWebGames

Recommended Posts

Posted

i am learning the switch statment... pleaet tell me if this is right...

 

<?php 
include "globals.php"; 
$_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; 
switch($_GET['x']) 
{ 
case 'lexus' : lexus (); break; 
case 'mustang' : mustang (); break; 
case 'fordgt': fordgt (); break; 
case 'fait' : fait (); break; 
default : index (); break; 
} 
function index() 
{ 
echo '<h3>GTA</h3>
'; 
echo' [url="?x=lexus"]Break into a lexus[/url]
'; 
echo ' <a hrerf="?x=mustang">Break into a mustang</a>
'; 
echo ' [url="?x=fordgt"]Break into a ford gt[/url]
'; 
echo ' [url="?x=fait"]Break into a fait[/url]
'; 
} 
function lexus() 
{ 
echo'lol'; 
} 
?>

 

NOTE:its not finished!

Posted
i am learning the switch statment... pleaet tell me if this is right...

 

include "globals.php"; 
$_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; 
switch($_GET['x']) 
{ 
case 'lexus' : lexus (); break; 
case 'mustang' : mustang (); break; 
case 'fordgt': fordgt (); break; 
case 'fait' : fait (); break; 
default : index (); break; 
} 
function index() 
{ 
echo 'GTA

'; 
echo' Break into a lexus
'; 
echo ' Break into a mustang
'; 
echo ' Break into a ford gt
'; 
echo ' Break into a fait
'; 
} 
function lexus() 
{ 
echo'lol'; 
} 
?>

 

NOTE:its not finished!

that should work but you dont have to use 2 lines on it you can just use

 if(!$_GET['action']) or name it whatever u want 

instead of useing

 $_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false; 
switch($_GET['x']) 

 

then all the links would be http://blabla.com/index.php?action= or whatever you called it. hope that helps

Posted

2 lines

so is this right?

 

<?php
include "globals.php";
if(!$_GET['action']) 
{
case 'bread' : bread (); break;
case 'chicken' : chicken (); break;
case 'ham' : ham (); break;
case 'crisps' : crisps (); break;
?>
Posted
$_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false;

seems abit far lol but i normally add in_array for a little extra security

You don't need in_array() for a little extra security, while using switch() there. It's not needed, when using switch if x value isn't in switch, it will just use the default value.

Posted
$_GET['x'] = isset($_GET['x']) && ctype_alpha($_GET['x']) ? strtolower(trim($_GET['x'])): false;

seems abit far lol but i normally add in_array for a little extra security

You don't need in_array() for a little extra security, while using switch() there. It's not needed, when using switch if x value isn't in switch, it will just use the default value.

depends on if they are using switch as Above one didn't but you are right.

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...