- is_array() :- Finds whether a variable is an array
- Description:-is_array( var) :-Returns TRUEif varis an array, FALSEotherwise. - is_float() :- Finds whether a variable is a float
- Description;-is_float(var) Returns TRUEif varis a float, FALSEotherwise. - is_int() :- Find whether a variable is an integer
- Description:-is_int(var) Returns TRUEif varis an integer FALSEotherwise. - is_string() :- Finds whether a variable is a string
- Description:-is_string(var) Returns TRUEif varis a string, FALSEotherwise. - is_object() :- Finds whether a variable is an object
- Description:-is_object(var) Returns TRUEif varis an object, FALSEotherwise. - is_bool() :- Finds out whether a variable is a boolean
- Description:-is_bool(var) Returns TRUEif the varparameter is boolean. - is_null :- Finds whether a variable is NULL
- Description :- is_null(var) Returns TRUEif varis null , FALSEotherwise See the null type when a variable is considered to be NULLand when not.
Global Variables
- A global variable can be accessed in any part of the program.
- However, in order to be modified, a global variable must be explicitly declared to be global in the function in which it is to be modified.
- This is accomplished, conveniently enough, by placing the keyword GLOBAL in front of the variable that should be recognized as global.
- Placing this keyword in front of an already existing variable tells PHP to use the variable having that name.
<?php
$somevar=15;
functionaddit()
{
GLOBAL$somevar;
$somevar++;
print"Somevar is $somevar";
}
function addit1()
{
GLOBAL $somevar;
$somevar++;
print "Somevar is $somevar";
}
addit();
addit1();
?>
Output:-
Some var is 16
Some var is 16
Static variables
- A static variable retains its value between calls to a function but is visible only within that function.
- You can declare a variable static with the static keyword.
For example : function update_counter
<?php
function update_counter ( )
{
static $counter = 0;
$counter++;
echo "Static counter is now $counter";
}
$counter = 10;
update_counter( );
update_counter( );
echo “counter is $counter";
?>
Output:-
Static counter is now 1 Static counter is now 2 Global counter is 10
Comments
Post a Comment