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!
<?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();)-------
$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>";
}
}
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.
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)
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:
$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.