switch VERY-Basic problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
refael_gold
Forum Newbie
Posts: 3
Joined: Thu May 20, 2010 2:56 am
Location: israel

switch VERY-Basic problem

Post by refael_gold »

Code: Select all

<?php 
$index=4;

switch ($index)


for ($m=0; $m<100;$m++)
{
 case $m :  echo "lets keep run the numbers now we are in:".$m ; break; 
 }
 

?>
i'm started to learn PHP by lynda.com 2 days ago and really need some help
Q:

1.i have tried to put 100 options at the case part and it didnt run
i try to put {} at the switch and it didnt help also...
i know i can do staff like this at java but have no idea why its not work.
it must be a way to put case numbers with a loop and i will be glad to hear about it

2.i need some method to put value at $index by the client ------(like in java index=scan.nextInt();)-------
User avatar
wattee
Forum Newbie
Posts: 12
Joined: Mon Nov 02, 2009 5:00 am

Re: switch VERY-Basic problem

Post by wattee »

do u mean something like this?

Code: Select all

$index = 4;

switch ($index) {
	case 1:
	break;
	
	case 2:
	break;
	
	case 3:
	break;
	
	case 4:
	for ($m=0; $m<100;$m++)
	{
		echo "lets keep run the numbers now we are in:".$m. "<br>";
	}

}
or can you clarify what you want to do
refael_gold
Forum Newbie
Posts: 3
Joined: Thu May 20, 2010 2:56 am
Location: israel

Re: switch VERY-Basic problem

Post by refael_gold »

not all the code are showed...
1 second..

Code: Select all

<?php 
$index=4;

switch ($index)


for ($m=0; $m<100;$m++)
{
 case $m :  echo "lets keep run the numbers now we are in:"."<br/>".$m;break;
 }
 

?>
now its more clear?
Last edited by Benjamin on Thu May 20, 2010 10:51 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: switch VERY-Basic problem

Post by Benjamin »

Tell us why you are trying to do this. Your approach is not correct. This is possible, but it's not something you would ever want to do.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: switch VERY-Basic problem

Post by AbraCadaver »

Benjamin wrote:Tell us why you are trying to do this. Your approach is not correct. This is possible, but it's not something you would ever want to do.
I would be interested to know why this is needed as well, however I don't think it's possible inside a switch without using eval().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
refael_gold
Forum Newbie
Posts: 3
Joined: Thu May 20, 2010 2:56 am
Location: israel

Re: switch VERY-Basic problem

Post by refael_gold »

lets say i having a 100 options that i need to do "copy" to all cases...

i want to do it with FOR statement -how i do it?

its very helpful lets say i need to write some comment on 1-10 grades(for exmple) and 11-20 and so on and so on...
i want to write all the cases with a for(instad write it 100 times the CASE option)


tnx for trying to help
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: switch VERY-Basic problem

Post by AbraCadaver »

refael_gold wrote:lets say i having a 100 options that i need to do "copy" to all cases...

i want to do it with FOR statement -how i do it?

its very helpful lets say i need to write some comment on 1-10 grades(for exmple) and 11-20 and so on and so on...
i want to write all the cases with a for(instad write it 100 times the CASE option)


tnx for trying to help
Give us the real world code for 3 or 4 cases and explain why you need a switch with cases. If your example worked, it would be the same as just doing this:

Code: Select all

$index = 4;
echo "lets keep run the numbers now we are in:"."<br/>".$index;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply