Programming Articles - Page 1712 of 3366

PHP NULL

Malhar Lathkar
Updated on 19-Sep-2020 14:48:05

7K+ Views

Definition and UsageIn PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value been set to null by using unset() function.Syntax$var=NULL;It is possible to cast variable of other type to null, although casting null to other type has been deprecated from PHP 7.2. In earlier versions, casting was done using (unset)$var syntaxFollowing example shows how to assign NULL to a variableExample Live DemoOutputThis will produce following result −NULLFollowing example performs null variable to other primary variablesExample Live DemoOutputThis will ... Read More

PHP Iterables

Malhar Lathkar
Updated on 19-Sep-2020 14:41:10

982 Views

Definition and UsageFrom version 7.1 onwards, PHP provides a new pseudo-type called iterable. Any object (such as array) that implements Traversable interface is acceepted by it. This type uses foreach construct or a generator function that yields one value at a a time.SyntaxA function can have iterable as type of its parameter to let the function accept a set of values used in foreach statement. If the parameter doesn't support foreach loop, PHP parser throws TypeErrorExample Live DemoOutputThis will produce following result −PHP Java PythonA PHP function can also return an iterable data type such as array. We use is_iterable() function to ... Read More

PHP Integer Data Type

Malhar Lathkar
Updated on 19-Sep-2020 14:38:43

601 Views

Definition and UsageIn PHP, Integer is a scalar data type that represents a numeric constant represents a whole number wihout any fractional part. PHP allows an integer to be expressed in decimal, hexadecimal, octal or binary number system by prefixing appropriate symbol.By default Integer is assumed in decimal notation. For Hexadecimal, octal and binary number system, respectively 0x, 0 an 0b symbols are prefixed.SyntaxFor better readibility, integer literal may use "_" as separation symbol which will be omitted by PHP scanner while processing.PHP VersionUse of separation symbol "_" is avilable since PHP 7.40Following example shows integer literal representation in different ... Read More

PHP Floating Point Data Type

Malhar Lathkar
Updated on 19-Sep-2020 14:31:53

808 Views

Definition and UsageIn PHP, float data type represents any number with a provision to contain a fractional part. The fractional part may contain digits after decimal point, or may be represented in scientific notation using either e or E. For example 100 in scientific notation is 10e2.Size of a float depends on the hardware/OS platform, although precision upto 14 digits after decimal point is commonly found.Syntax//Literal assignment of float value to variable $var=5327.496; // standard notation $var1=5.327496e3; // Scientific notation $var2=5.327496E3; //Scientific notation $var3=5_327.496; //sepration symbolFor better readibility, integer literal may use "_" as separation symbol which will be omitted by ... Read More

PHP Callbacks/Callables

Malhar Lathkar
Updated on 19-Sep-2020 14:26:10

862 Views

Definition and UsageCallback is a pseudo-type in PHP. With PHP 5.4, Callable type hint has been introduced, which is similar to Callback. When some object is identified as callable, it means that it can be used as a function that can be called. A callable can be a built-in or user defined function or a method inside any class.The is_callable() function can be used to verify if the identifier is a callable or not. PHP has call_user_function() that accepts a function's name as a parameter.Following example shows a built-in function is a callable.Example Live DemoOutputThis will produce following result −bool(true)In following ... Read More

PHP Boolean Data Type

Malhar Lathkar
Updated on 19-Sep-2020 14:23:53

10K+ Views

Definition and UsageThis is one of the scalar data types in PHP. A boolean data can be either TRUE or FALSE. These are predefined constants in PHP. The variable becomes a boolean variable when either TRUE or FALSE is assigned.SyntaxResult of echoing TRUE value displays 1 while for FALSE it shows nothing. Using var_dump() function displays bool as type with valueBoolean constants are not case sensitive. That means TRUE is equivalent to true and FALSE is similar to FalseLogical operators return boolean valueCastingAny data type can be explicitly converted to boolean with the help of casting operator (bool) or (boolean), ... Read More

PHP Tags

Malhar Lathkar
Updated on 19-Sep-2020 14:19:48

9K+ Views

Definition and UsageA PHP code script is a text file having .php extension and is stored on web server. The PHP parser on server looks for special sequence of characters . These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser. PHP script within these tags can be embedded in HTML document, so that embedded code is executed on server, leaving rest of the document to be processed by client browser's HTML parser.SyntaxShort tagsPHP allows a using a shorter representation of opening tag PHP VersionThis setting is recommended to be Off for production ... Read More

PHP Escaping From HTML

Malhar Lathkar
Updated on 19-Sep-2020 14:16:46

1K+ Views

Definition and UsagePHP file can have mixed content with code within tags embedded in a HTML document. Code outside tags is ignored by the parser, leaving it to be interpreted by client browser. A HTML document can have multiple blocks of PHP, each inside tags.Syntax HTML block HTML block HTML block Every time opening PHP tag is encountered, parser starts rendering the output to the client until closing tag is reached. If code consusts of conditional statement, th parser determines which block to be skipped.Again till another opening tag comes, everything is treated ... Read More

PHP Operator Precedence

Malhar Lathkar
Updated on 19-Sep-2020 13:53:05

7K+ Views

IntroductionPrecedence of operators decides the order of execution of operators in an expression. For example in 2+6/3, division of 6/3 is done first and then addition of 2+2 takesplace because division operator / has higher precedence over addition operator +. To force a certain operator to be called before other, parentheses should be used. In this example, (2+6)/3 performs addition first, followed by division.Some operators may have same level of precedence. In that case, the order of associativity (either left or right) decides the order of operations. Operators of same precedence level but are non-associativem cannot be used next to ... Read More

PHP Increment/Decrement Operators

Malhar Lathkar
Updated on 19-Sep-2020 13:50:56

12K+ Views

IntroductionC style increment and decrement operators represented by ++ and -- respectively are defined in PHP also. As the name suggests, ++ the increment operator increments value of operand variable by 1. The Decrement operator -- decrements the value by 1. Both are unary operators as they need only one operand. These operators (++ or --) can be used in prefix or postfix manner, either as an expression or along with other operators in a more complex expression.Syntax$x=5; $x=5; $y=5; $x++; //postfix increment $y--; //postfix decrement ++$y; //prefix increment --$x; //prefix decrementWhen used independently, postfix and prefix increment/decrement operator ... Read More

Advertisements