<?php if ($a && $b) { echo "Hello world!\n"; } self::doSomething(); call_my_func(MY_CONST); $this->callOneThing()->callAnotherThing(); $this->callSomething()->callOtherSomething(); do_something($arg1, $arg2, $arg3); do_something($arg1); do_other_thing($argument1, $argument2, $argument3, $argument1, $argument2, $argument3, $argument1, $argument2, $argument3, $argument1, $argument2, $argument3); do_other_thing($argument1, $argument2, $argument3, $argument1, $argument2, $argument3, $argument1, $argument2, $argument3, $argument1, $argument2, $argument3); array_map(function ($arg) { return $arg[1]; }, array('11', '22'));
echo $b-- . '<br>'; //Descomentar 2 linhas abaixo para testar //if ($b < 7) // exit; //Encerra o script inteiro } //Output de 10 a 7 e encerra TODO o script echo '<hr>'; //---------------------------- $arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9); while (list($key, $value) = each($arr)) { if (!($key % 2)) { // salta numeros impares continue; //vai para o proximo elemento do loop } do_something($value); //executa somente nos pares } function do_something($value) { echo 'do_something(' . $value . ')<br>'; } echo '<hr>'; //---------------------------- $i = 10; while ($i > 0) { echo $i-- . '<br>'; } //Output de 10 a 1 echo '<hr>'; $j = 10;
switch ($variable) { // NOK {{Replace this "switch" statement with "if" statements to increase readability.}} case 0: do_something(); break; default: do_something_else(); break; } switch ($variable) { } switch ($variable) { // NOK case 0: do_something(); break; default: do_something_else(); break; } switch ($a) { // OK case 0: do_something(); break; case 0: default: do_something_else(); break; }
<?php do_something(function ($argument) { if ($argument) { do_something_else(); } }); $greet = function ($name) { echo "Hello, {$name}!"; };
<?php function do_something($var, callable $callback = NULL) { if ($callback) { $callback(3); } } do_something(3, function ($callvar) { var_dump($callvar); });
echo 'a == ', $a, '<br />'; $arr = array('one', 'two', 'three', 'four', 'stop', 'five'); while (list(, $val) = each($arr)) { if ($val == 'stop') { break 1; } echo "{$val}<br />\n"; } function do_something(&$arg) { $retval = $arg; $arg = $arg + 1; return $retval; } $c = 3; $d = do_something($c); echo $c, " ", $d; function incr_a($inc) { $e = $e + $inc; } $e = 0; incr_a(10); echo "<br />\n"; echo $e; echo "<br />\n"; $x = 1; if ($x == 1) { echo "True <br />"; } else { echo "False <br />";
*/ public static function media() { return array('js' => array('demo.js'), 'css' => array(array('screen' => 'demo.css', 'print' => 'print.css'))); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { /** * Bind the form to the POST data. */ $form = new DemoForm($_POST); if ($form->isValid()) { /** * Do something with the form data. */ do_something($form->cleaned_data); } } else { /** * Instantiate an unbound form. */ $form = new DemoForm(); } ?> <html> <head> <?php echo $form->media; ?> </head> <body>
$string = str_replace($string[$i], substr($string[$i], 0, 3), $string); } return $string; } $days_of_week = stringParse($days_of_week); foreach ($days_of_week as $stry) { echo $stry . '<br />'; } function do_something(&$arg) { $retval = $arg; $arg = $arg + 1; return $retval; } $a = 3; $b = do_something($a); echo $a, " ", $b; $_GET['foo'] = 'get'; $_POST['bar'] = 'post'; echo $_REQUEST['bar']; $aa = 1; if ($aa == 1.0) { echo "<br/>true"; } else { echo "<br/>false"; } if ($aa === 1.0) { echo "<br/>true"; } else { echo "<br/>false"; }