PHP Functions frequently asked and Important
PHP Functions Frequently asked and Important are:
phpinfo()
This built-in function output PHP’s configuration information.
phpinfo ( int flags = INFO_ALL) : bool
Display all information about current state of PHP . For the example PHP compilation options and extensions, server information and environment, PHP version, paths, master and local values of configuration options, http headers etc.
phpinfo() is used to check configuration settings . It is important debugging tool as it contains all EGPCS ( Environment, GET ,POST, Cookie, Server) data.
Example :
<?php // Show all information phpinfo(); ?>
ini_set()
We some time need to modify PHP settings mentioned in php.ini file using ini_set(). This function takes two string arguments first one is the name of setting and second one is new value of string.
<?php ini_set('max_execution_time', 0); ini_set('display_errors', '1'); // check new set value echo ini_get('display_errors'); echo ini_get('max_execution_time'); ?>
count()
This built-in php function used to count all element in an array .
Syntax :
count($array, mode);
Parameters :
Parameter | Description |
array | An array or countable object |
mode | This is optional and takes two values 0 or 1 ( COUNT_RECURSIVE). If mode is set to 1 it recursively count the array. Useful for counting all element of multidimensional array. |
Return Values :
It returns total numbers of element of an array. If value is null i.e. array is empty, 0 will be returned.
Example 1 : Counting normal
<?php // PHP programme to normal count() $array = array("Php", "Java", "Python", "HTML", "MYSQL"); print_r(count($array)); ?>
Output :
5
Example 2 : Recursive Count
<?php // PHP program to recursive count() $array = array('language' => array('Php', 'Java', 'C'), 'rank' => array('8', '2', '1')); // recursive count - mode as 1 echo("Recursive count: ".count($array,1)."\n"); // normal count - mode as 0 echo("Normal count: ".count($array,0)."\n"); ?>
Output :
Recursive count: 8 Normal count: 2