MemoryRefresh!

Variables



Questions Answers 0%

Pages   0 from 51
Questions   0 from 84

Reset



* Variable Scope PHP has three variable scopes: the global scope, function scope, and class scope. * Variable-length Argument Lists You can create a function that accepts a variable number of arguments, depending on the circumstance. A typical example of this behaviour is exhibited by the printf() family of functions.
<?php echo sprintf("%s %s is %d old", "John", "Smith", 10); // Output: John Smith is 10 old PHP provides three built-in functions to handle variable-length argument lists: func_num_args(), func_get_arg(), func_get_args()
<?php function myArray() { $arr = array(); $i = 0; if (func_num_args() == 0) { $arr[] = "Hello World"; } if (func_num_args() > 0) { while($i < func_num_args()) $arr[] = "Hello " . func_get_arg($i++); } return $arr; } print_r(myArray()); // [Hello World] print_r(myArray("John", "Mary")); // [Hello John, Hello Mary] It is rather important to keep in mind that variable-length argument lists are full of potential pitfalls. While they are very powerful, they do tend to make your code confusing.
Questions

Related pages

Definition !
Variables !
Anonymous !
Reference !


0% 100%
 
 
0 pages 51 pages
1) Get function arguments count




2) Get the first function argument





Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


* Variable Scope PHP has three variable scopes: the global scope, function scope, and class scope. * Variable-length Argument Lists You can create a function that accepts a variable number of arguments, depending on the circumstance. A typical example of this behaviour is exhibited by the printf() family of functions.
<?php echo sprintf("%s %s is %d old", "John", "Smith", 10); // Output: John Smith is 10 old PHP provides three built-in functions to handle variable-length argument lists: func_num_args(), func_get_arg(), func_get_args()
<?php function myArray() { $arr = array(); $i = 0; if (func_num_args() == 0) { $arr[] = "Hello World"; } if (func_num_args() > 0) { while($i < func_num_args()) $arr[] = "Hello " . func_get_arg($i++); } return $arr; } print_r(myArray()); // [Hello World] print_r(myArray("John", "Mary")); // [Hello John, Hello Mary] It is rather important to keep in mind that variable-length argument lists are full of potential pitfalls. While they are very powerful, they do tend to make your code confusing.



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com