Switch Case And Array

I have an array and I need to be able to switch case based on the array values. I've tried the following but something is wrong and it's not working:

$section = array(
'varOne'     => 'This is variable One',
'Two'     => 'Work with variable Two',
'var_Three' => 'Post var three',
'myDefault' => 'This is my default');

switch($section) {
case 'postProject':
   echo section['varOne'];
case 'Two':
   echo $section['Two'].$addSomething;
case 'var_Three':
   echo $section['var_Three'].$more;
   echo $section['myDefault'];

What am I missing? Basicly I'd like to match case by array's KEY adn output areray's VALUE... Honestly I'm not on a short hand with arrays.


Switch Statement > Include Multiple Case Matches In A Single Case?

I'd like to pass multiple values in a single switch case. I realize its not possible they way I'm trying to do it. Is there another way, short of placing each case on its on line?

case 'test1', 'test2':[code]....

View 5 Replies View Related

Switch My Case

I haven't used switch before, so I thought I'd give it a go. But I ran into some trouble. The case is like this: I have a search results page where, depending on the no of hits, different texts should be printed. Perfect for switch I thought, but I need to use a different range for each case.

Some code:
// connect and query code not included...

switch ($numrows) {
case $numrows==0:
$traff='Do it again...'
case $numrows==1:
case $numrows<=25:
$traff='Should be here somewhere...'
case $numrows<=50:
$traff='a little too many...'
case $numrows>51:

echo "$numrows $traff"; So I always know how many hits I get and this works except when I get no hits. The value of $numrows shows 0, but $traff shows 'Great!!'Why? Or am I doing this wrong?

View 7 Replies View Related

Using The Case Switch

What i'm looking for is an example of what a link coming from some page to a form page holding a variable that i can use in a switch function after the form is submitted would look like. The action on the form takes me to a script where i will need this variable.

switch ($var)
case "1"
use this $var1; //came from this page
case "2"
use this $var2; //came from this page
print "error";

View 6 Replies View Related

Switch Case

I have a switch statement and its probably not possible to do what I want to do but I thought I'd ask. I have 2 similar cases (date and datetime) so if its date or datetime I want to show the date, then after that only put the time if its datetime. Now if I wanted the time to go first.

View 7 Replies View Related

Switch Case - How Does Value Get Placed

I'm looking at trying out using switch case as a way to turn a division either on or off or with an include a file thing. The information I've seen so far is basic. That is, the discussion is on it's primary use. Using a standard link, how does one embed the variable into the link to pass the value on to the action? [URL]... When google is clicked on, the google division shows. When yahoo is clicked the yahoo division is shown.Where and how does the value get placed?

View 1 Replies View Related

Php Case Switch

I'm implemening an update profile section on my site and I'd like to use switch/case method. e.g. page.com?update=success or page.com?update=failure, when I use the $_GET['update'] it works fine, however what of someone changes the url manually to .com?update=somethingelse ?

How can I stop people getting access to other pages/cases manually.

View 2 Replies View Related

Switch Case More Than 1 Value In The Case?

I have the next situation. I have the variable, which can has the next values ('Weekly', 'Monthly', 'Quarterly', 'Annual'). And I have another int variable, which can has values from 1 to 10. Now I do the next things:

switch ($var2) {
case 1:
$var3 = 'Weekly';
case 2:


View 2 Replies View Related

Problem With Switch/case, Want It Instead Of If

I have this code that fetches a nationID from my table.
Depending on what ID it is... it displays a country flag.

View 4 Replies View Related

Switch And Case Problem

Can anyone give me a helping hand with this code

I want the script to verify a username and password using a switch and case statement.

if the username and password is matched I want to move on to the next section of the site. If there is no match I want it to ask for the username and password again.

The trouble is Im not getting the desired results with the switch and case

echo "
require "./config.inc.php";
$db_connect = mysql_connect ($host,$user,$passwd);
mysql_select_db($database, $db_connect);
if ( $rep_name )
switch ($page) {
case "login":
$result=mysql_query("select * from rep where rep_name='$rep_name'",$db_connect) or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
if ($row["rep_passwd"] != $rep_passwd) {
$failure = 1; break;
echo "successful login";
//echo "Wrong username";
if ($failure == 1)
{ echo "Wrong details"; }
else { echo"
<form method='post' action='$PHP_SELF?page=login'>
Username: <input type='text' name='rep_name'><br>
Password: <input type='password' name='rep_passwd'><br>
<input type='submit' value='Submit'>
echo "

View 4 Replies View Related

Switch / Case Errors

For some reason I can never get the "Switch / Case" functions to work for me. Can some one tell me whats wrong with this: PHP Code:

View 6 Replies View Related

Using If Statement With Switch / Case

Is it possible to add an if statement inside of switch case? Below is a small piece of a pretty long switch statement that has about 12 different cases. But I only want it to change/switch cases if certain conditions are met for each particular case.

Can I just add an if statement within the case?

case 'forcetrade': $next_state = 'forceplace'
case 'forceplace': $next_state = 'attacking'

View 5 Replies View Related

Case Switch Best Practice

I don't know what to call what I want to do, so I'd appreciate suggestions for keywords so that I can study up on it. if it's easy your input of course. I want to have a table of contents plus 10 articles in one php file. Depending on which article link the visitor clicks on, the page will refresh and that section of the php code will show the appropriate article on the page. I've gotten as far as this has something to do with blah.php?article2. I've also found that case switch does this, but that looked very messy for something that seems so simple.

View 4 Replies View Related

Add Two Values For One Case Using Switch?

im trying to create a website using switch commands to navigate with the contents displayed in a table via echo content. everything works fine. but one of the pages consists of multiple pages. The address looks like this website/index.php?content=home etc. but i want to make it like this for the page consisting multiple pages website/index.php?content=home&page=1

my index code:

case "home":
$content = file_get_contents('home.php');...............

but when i do it like this the echo command shows me the code of the home.php but not the one of the page i wanna load inside of it.

View 4 Replies View Related

Switch Case / Add Regexp?

how can fix it or add regexp ?

case substr($rrr['url'],-4)=='.jpg' || '.png' || '.gif' || '.tif' || '.tiff':

View 4 Replies View Related

Use Switch Statement And Case Instead Of If And Else

I am trying to understand how to use switch and case instead of if and else. I have this code that works


I get this error... Parse error: parse error, expecting `'('' in C:wampwww estmaintain.php on line 129. WHich in this case matches up with the 'case empty:' line I have two questions... First how do I change the above code so that it works like the if else statement?

View 5 Replies View Related

Switch Case With Three Parameters?

Is it possible to use three parameters in switch-case, like this:

switch($var1, $var2, $var3){
case true, false, false:
echo "Hello";

If not, should I just use if-else or is there a better solution?

View 7 Replies View Related

Using Variable In Another Switch Case?

Yes i have this line in my first "upload" case of the switch:

$file_name = $USER . "-".rand(1, 888).".jpg";

Then in my switch case "crop" (that takes care of the image you crop), I wish to replace the uploaded one with the new one, simply by uploading with same name. Now i cant use $file_name in the case "crop" so how can I do this?

View 2 Replies View Related

Two Values In The Case Of Switch?

If "car" or "ferrari" as an input, it should print "car or ferrari". How can I achieve it?

$car ='333';

View 5 Replies View Related

Switch, Same Value For Multiple Case?

switch ($i) {
case A:
$letter = 'first';

Is there any way to shorten first three cases? They have the same values inside.

View 2 Replies View Related

Header() Ignored In Switch/case Statement

Can anyone tell me why in the 'unreg' part of this switch/case statement, the header() is being completely ignored? I am including the code for for the switch/case, plus the code on the page referenced in the header() redirect. PHP Code:

View 5 Replies View Related

Automaticly Create A SWITCH Case

I tried to automaticly create a SWITCH Case with all files in a specific directory. PHP Code:

View 5 Replies View Related

Switch And Case With Special Characters...

i have a switch and case section. the switch parameter is a veriable called $Char and a character it is (i.e. "e" or any other character (not its ascii value)). how can i put the chars $ " in the case command?

View 1 Replies View Related

Importing StyleSheet Using Switch/Case

I'm using a simple radio group buttons to let the user select the stylesheet they want.
Then the switch/case script imports the desired stylesheet. What is wrong with this script (because it doesn't work)?

Okay I know it is the "@import/blue.css"; but I can't figure out what it should be. Is there a site that explains how to do it?

View 1 Replies View Related

Switch Case Image Maps

Seems my switch case statement isn't working, and I can't see why it isn't.

The App: The webapp I am making is a webpage that uses imagemaps as a menu system. The menu is basically a table with 6 columns and 5 rows. Each row is a seperate image. When a cell of the "table" is clicked, the options under that tables category are displayed as pictures. I did this by passing a variable and reloading the page when a hotspot on the image map is clicked. When the page reloads a switch case is used to display either a row with a cell selected, or the default unselected row.

Below is the select case that will not work properly. The Map functions all work (they have been tested) and pass the variable.

PHP Code: .....

View 4 Replies View Related

Switch Statement - First Case Always Gets Executed

here's part of my script:

switch ($member)
case (('justus') ¦¦ ('Justus')):
echo "bla";

case (('tsavo') ¦¦ ('Tsavo')):
echo "blah";

and here's my problem: no matter what $member equals, the first case always gets executed. what am i doing wrong?

View 1 Replies View Related

Default: Switch To Other Case Option?

Say I have something like this:

switch($_GET['func']) {
case 'foo':
case 'orange':
if($_GET['aubergine'] == 'catdog') {

How should I implement do_default_option()? In case you didn't get it, I want do_default_option to skip to the default: part of the switch() statement.

View 2 Replies View Related

Switch With Multiple Values Ver Case?

How would you do this PHP switch statement? Also note that these are much smaller versions, the 1 I need to create will have a lot more values added to it.

Version 1:
switch ($p) {
case 'home':
case '':
$current_home = 'current';
case 'users.online':

View 8 Replies View Related

Syntax Error And Switch Case?

I can't find a reason for why I'm getting this error:

Parse error: syntax error, unexpected '{' on line 4

if I should use a switch case in my code instead of what I have at the moment, or leave it as is?

$error = "An error occurred, please press f5 to refresh the page and try again.";


View 1 Replies View Related

Switch Case - Access Control Of Page

I want to control the access in php website. I have a solution right now with switch case.


But when i have so many pages, it becomes difficult to manage them. Do you have better solutions? Right now, i develop the application using php4. And i want to use php5.

View 4 Replies View Related

Magento - HTML CSS Beginner USE CASE / SWITCH / IF ELSE?

My idea was to use CSS to show the TAB over the relevant Navigation menu item based on the URL.However, one URL always changes, so I wanted to somehow use an ifelse statement.I've come up with two methods that I think could work, could any experts tell me what they would think is best and how they would implement it?

Method 1
<div id="nav">
<ul id="mainnav">
<li><a href="index.php" title="Welcome page" <?php if ($page == 'index.php') { ?>class="active"<?php } ?>>Welcome</a></li>

View 4 Replies View Related

Copyrights 2005-15 www.BigResource.com, All rights reserved