PHP Basic | PHP Function |
PHP Looping | PHP Condition statement |
/* echo() function outputs one or more strings. */ echo "hello world";//output hello world /* declaring variable */ $string = "world";/* echoing variables */ $string = "world";echo "hello ".$string; //output hello world | /* passing variable to functions */ function test($string) { echo "hello ".$string; } test('world'); //output hello world/* returning values */ function add($number) { return 1 + $number; } add(1); //output 2 |
/* user-defined fucntion */ function test(){echo "hello world"; } /* calling user-defined fucntion */ test();//output hello world /* returning values */ function add(){ return 1 + 1; } add(); //output 2 | $a = 1; $b = 2; /* if */ if ($a > $b) echo "a is greater than b";/* else */ if ($a > $b) { echo "a is greater than b"; } else { echo "a is NOT greater than b"; }/* elseif */ if ($a > $b) { echo "a is greater than b"; } elseif ($a == $b) { echo "a is equal to b"; } else { echo "a is less than b"; }/* switch */ switch ($i) { case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; case 2: echo "i equals 2"; break; } |
/* for loop */ for ($i = 1; $i <= 10; $i++) {echo $i; } /* while loop */ $i = 1;while ($i <= 10) { echo $i++; } /* do..while */ $i = 0;do { echo $i; } while ($i > 0); /* foreach */ $arr = array("1", "2", "3");foreach ($arr as $value) { echo "Value: $value\n"; } /* break */ break ends execution of the current for, foreach while, do..while or switch structure. break; /* continue */ continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the beginning of the next iteration. continue; | |
0 comments:
Post a Comment