Re: Operations in PHP Hi, FUNCTIONS
A function in PHP can be built-in or user-defined; however, they are both
called the same way.The general form of a function call is
func(arg1,arg2,…)
The number of arguments varies from one function to another. Each
argument can be any valid expression, including other function calls.
Here is a simple example of a predefined function:
$length = strlen("John");
strlen is a standard PHP function that returns the length of a string.
Therefore, $length is assigned the length of the string "John": four.
Here’s an example of a function call being used as a function argument:
$length = strlen(strlen("John"));
You probably already guessed the result of this example. First, the inner
strlen("John") is executed, which results in the integer 4. So, the code simpli-
fies to
$length = strlen(4);
strlen() expects a string, and therefore (due to PHP’s magical autoconversion
between types) converts the integer 4 to the string "4", and
thus, the resulting value of $length is 1, the length of "4".
__________________ Regards,
Senraj.A
Last edited by senraj : 05-09-2008 at 05:16 AM.
|