Etiqueta: PHP

Returning values

Values are returned by using the optional return statement. Any type may be returned, including arrays and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called. See return() for more information. Note: If the return() is omitted the value NULL will be

Continuar leyendo...

Function arguments

Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists are also supported, see also the function references for func_num_args(), func_get_arg(), and func_get_args() for more information. Example #1 Passing arrays

Continuar leyendo...

example ,Conditional functions on PHP

<?php $makefoo = true; /* We can’t call foo() from here since it doesn’t exist yet, but we can call bar() */ bar(); if ($makefoo) { function foo() { echo «I don’t exist until program execution reaches me.\n»; } } /* Now we can safely call foo() since $makefoo evaluated to true */ if ($makefoo)

Continuar leyendo...

include function on PHP

The include() statement includes and evaluates the specified file. The documentation below also applies to require(). Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include() will finally check in the calling script’s own directory and the current working

Continuar leyendo...

require on PHP

require() is identical to include() except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue. See the include() documentation for how this works.

Continuar leyendo...

return on PHP

If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file. If called from the global scope, then execution of the current script file is ended.

Continuar leyendo...

declare

The declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs: declare (directive) statement The directive section allows the behavior of the declare block to be set. Currently only two directives are recognized: the ticks directive (See below

Continuar leyendo...

switch

The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

Continuar leyendo...

continue

continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration. Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue. continue accepts an optional numeric argument which

Continuar leyendo...

break

break ends execution of the current for, foreach, while, do-while or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. <?php $arr = array(‘one’, ‘two’, ‘three’, ‘four’, ‘stop’, ‘five’); while (list(, $val) = each($arr)) { if ($val == ‘stop’) { break; /*

Continuar leyendo...