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
Programming Articles - Page 1713 of 3366
2K+ Views
IntroductionThere is one Execution operator defined in PHP. A string inside back-ticks (``) is treated as a DOS command (a shell command in UNIX/Linux) and its output is returned. This operator is similar in operation to shell_exec() function in PHP.Following code executes DIR command and returns result as string.ExampleOutputFollowing result will be displayedVolume in drive C is Windows 10 Volume Serial Number is 540D-CE99 Directory of C:\xampp\php 01/27/2016 05:32 PM 18, 869 CompatInfo.php 07/08/2020 06:40 PM 64 test.php 07/11/2020 02:13 PM 48 testscript.php 03/30/2013 05:59 PM 1, 447 webdriver-test-example.php 4 File(s) 20, 428 bytes 0 Dir(s) 178, 002, 157, 568 ... Read More
2K+ Views
IntroductionIn PHP @ symbol is defined as Error Control Operator. When it is prefixed to any expression, any error encountered by PHP parser while executing it will be suppressed and the expression will be ignored.Following code tries to open a non-existing file for read operation, but PHP parser reports warningExample Live DemoOutputFollowing result will be displayedHello World PHP Warning: fopen(nosuchfile.txt): failed to open stream: No such file or directory in /home/cg/root/1569997/main.php on line 2Prepending @ symbol to fopen() expression suppresses error message and statement itself is ignoredExample Live DemoOutputFollowing result will be displayedHello World
11K+ Views
IntroductionAlmost everything in a PHP script is an expression. Anything that has a value is an expression. In a typical assignment statement ($x=100), a literal value, a function or operands processed by operators is an expression, anything that appears to the right of assignment operator (=)Syntax$x=100; //100 is an expression $a=$b+$c; //b+$c is an expression $c=add($a, $b); //add($a, $b) is an expresson $val=sqrt(100); //sqrt(100) is an expression $var=$x!=$y; //$x!=$y is an expressionexpression with ++ and -- operatorsThese operators are called increment and decrement operators respectively. They are unary operators, needing just one operand and can be used in prefix or ... Read More
5K+ Views
IntroductionThe goto statement is used to send flow of the program to a certain location in the code. The location is specified by a user defined label. Generally, goto statement comes in the script as a part of conditional expression such as if, else or case (in switch construct)Syntaxstatement1; statement2; if (expression) goto label1; statement3; label1: statement4;After statement2, if expression (as a part of if statement) is true, program flow is directed to label1. If it is not true, statement3 will get executed. Program continues in normal flow afterwards.In following example, If number input by user is even, program ... Read More
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