Jump to content
View in the app

A better way to browse. Learn more.

The Uniform Server Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

how to include a switch statement

Featured Replies

how to include a switch statement

 

say i have a code name test1.php

 

<?php 
switch ($i): 
case 0: 
echo "i equals 0";	
break; 
case 1: 
echo "i equals 1"; 
break; 
case 2: 
echo "i equals 2"; 
break; 
default: 
echo "i is not equal to 0, 1 or 2"; 
endswitch; 
?>

 

and another one name test.php

 

<?php include ("test1.php?i=1"); ?> 
<?php include ("test1.php?i=0"); ?>

 

would it work if not what would work i have serched all over but no help to be found :)

IPB Image

 

IPB Image

if you like this Uniform Server User Sing take em i do not mind share

IPB Image

 

IPB Image

The switch is a block statement; hence pop it in curly braces.

The last two lines look wrong!

 

Format takes the following form: expression ? true part : false part;

Hence you would have something similar to this for your includes:

($i=="5")? include "mpg1.php": include "mpg2.php";

 

Working example you could try:

 

Save to www as test.php

 

<?php
$i=2;
switch ($i){
case 0:
echo "i equals 0";	
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
default:
echo "i is not equal to 0, 1 or 2";
}

($i=="5")? include "mpg1.php": include "mpg2.php";
?>

 

Save to www as mpg1.php

 

<?
print "<br>";
print "This is the true part";
?>

 

Save to www as mpg2.php

 

<?
print "<br>";
print "This is the false part";
?>

 

Change $i=5;

 

All the best

Ric :)

RIC: the grammar using endswitch is right.

 

override: I think you will solve this with this code:

$i = $_GET['i'];
switch($i)....

 

then if you use "include(test1.php?i=1);" in your test.php then you will see "i equals 1" as a result.

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.