
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

2K+ Views
IntroductionConditional execution of one or more statements is a most important feature of any programming language. PHP provides this ability with its if, else and elseif statements. Primary usage of if statement is as follows −Syntaxif (expression) statement;The expression in front of if keyword is a logical expression, evaluated either to TRUE or FALSE. If its value is TRUE, statement in next line is executed, otherwise it is ignored. If there are more than one statements to be executed when the expression is TRUE, statements are grouped by using additional pair of curly brackets, if (expression){ statement1; ... Read More

304 Views
IntroductionConstants are represented literally in an assignment expression such as $x=10 or $name="XYZ" where 10 and XYZ are numeric and string constants assigned to variables. In PHP, it is possible to define a constant with a user defined identifier with the help of define() functionSyntaxdefine ( string $name , mixed $value [, bool $case_insensitive = FALSE ] ) : boolparametersSr.NoParameter & Description1namename of the constant.2valuevalue of the constant may be any scalar value (integer, float, string etc) or array3case_insensitiveConstant identifiers are case sensitive by default. If this parameter is set to true, name and NAME are treated similarlyReturn ValueFunction returns ... Read More

11K+ Views
IntroductionIf name of a variable has parentheses (with or without parameters in it) in front of it, PHP parser tries to find a function whose name corresponds to value of the variable and executes it. Such a function is called variable function. This feature is useful in implementing callbacks, function tables etc.Variable functions can not be built eith language constructs such as include, require, echo etc. One can find a workaround though, using function wrappers.Variable function exampleIn following example, value of a variable matches with function of name. The function is thus called by putting parentheses in front of variableExample Live ... Read More

22K+ Views
IntroductionPHP has a large number of built-in functions such as mathematical, string, date, array functions etc. It is also possible to define a function as per specific requirement. Such function is called user defined function.A function is a reusable block of statements that performs a specific task. This block is defined with function keyword and is given a name that starts with an alphabet or underscore. This function may be called from anywhere within the program any number of times.Syntax//define a function function myfunction($arg1, $arg2, ... $argn) { statement1; statement2; .. .. return $val; } ... Read More

6K+ Views
IntroductionA function in PHP can be defined to accept input from calling environment/script in the form of arguments. These arguments are given as comma separeted list inside the parentheses in front of name of function. Note that while calling a function, same number of arguments must be passed to it.PHP supports calling a function by passing value, reference, arguments with default value and by passing variable number of arguments.function with argumentsIn following example, a function is defined with two formal arguments. When this function is called by passing the arguments by value. Arguments of function become its local variables. Hence, ... Read More

3K+ Views
IntroductionThe purpose of return statement in PHP is to return control of program execution back to the environment from which it was called. Upon returning, execution of expression following the one which invooked other function or module.If return statement occurs inside a function, execution of current function is terminated, handing over the control back to the environment from which it was called. The return statement may have an exprssion as optional clause in front of it. In that case, value of the expression is also returned in addition to the control.If encountered in an included script, execution of current scripts ... Read More

381 Views
IntroductionThe require_once statement in PHP is similar in functioning to that of require statement. Only difference is, if a file has been already included for processing, it will not be included again.Note that a file included with either include or require statement will also be not included again even if require_once statement is used.Other behaviour of require_once statement is similar to require statement .require_once ExampleIn following example main php script includes test.phpExample Live Demo //test.php OutputThis will produce following result when main script is run from command line −inside main script now including with require_once test.php script File included try to include ... Read More

306 Views
IntroductionEffect of require statement is similar to include statement in PHP. However, there is one main difference. If the parser fails to find required file, it produces a fatal error thereby termination of current script. The include statement on the other hand emits a warning in case of failure to find file and execution of current script continues.PHP parser tries to locate the file in current folder by default and further in directories mentioned in include_path setting of php.ini, as in case of include statement. If file asked for is not available in current folder as well as include_path folders, ... Read More

350 Views
IntroductionJust as the include statement, include_once also transfers and evaluates script written in one file in another, the difference in two lies in the fact that include_once prevents same file from reloading if already done. As the name indicates, a file will be included only once even if one tries to issue include instruction again.The include_once statement is typically used to set up global variables, enable libraries or any such activity that is expected to be done in the beginning of execution of application.Other than this, behaviour of include_once statement is similar to include statement.include_once ExampleIn following example testscript.php is ... Read More

306 Views
IntroductionIt is possible to break binding between the content and variable by using unset() function. The unset() function doesn't destroy the content but only decouples variable from it.Example Live DemoOutputAfter unsetting, $b can be used as normal vaiablebefore unsetting : 10 10 after unsetting : 10 20Reference can also be removed by assigning variable to NULLExample Live DemoOutputResult of above script is as followsx and y are references 100 x: 200 y: