Get time duration between 2 dates in php

We will show you how to get the time difference between to date in PHP.
For this, you need 2 dates From date and To dates. We will create a common function,  you just need to add the from date and to date in it then it will show you the result in an array. You can use this function anywhere in your code.

continue reading.

PHP Syntax

Basic PHP Syntax A PHP code starts with <?php and ends with ?>: <?php // PHP code write here ?> PHP files extension is ".php". A PHP file contains HTML tags, and some PHP code.  continue reading.

PHP Comments

Comments in PHP Comment code in PHP is a line that is not executed in the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: Let others understand your code Remind yourself of what you did – Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code PHP supports several ways of commenting: Live Demo <?php // This is a single-line comment # This is also a single-line comment /*This is a multiple-lines comment block*/ ?>continue reading.

PHP Variables

PHP Variables Variables are use to store the value Creating PHP Variables In PHP, a variable starts with the $ sign, followed by the name of the variable: Example Live Demo <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?> After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5. Note: When you assign a text value to a variable, put quotes around the value. Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it.continue reading.

PHP $ and $$ Variables

The $a is a variable with the $a  name that stores the value like string, int, float, etc. The $$aa is a reference variable that stores the value of the $variable inside it. Examples. <?php $a = “xyz”; $$b = 50; echo $a.” “; echo $$b.” “; echo $xyz; ?> In the above example, we have assigned a value to the variable a as xyz. The value of the reference variable $$b is assigned as 50. Now we have printed the values $a, $$b and $xyz.  

continue reading.

PHP echo and print

In PHP have two way to get the output:- echo print Echo: In ‘echo’ statement is a language construct and never behaves like a function, hence no parenthesis required. The end of the echo statement the semi-colon (‘;’) is needed. We can use ‘echo’ to output strings or variables. Below are some of the usage of echo statement in PHP: Display Text The following example shows how to output text with the echo command (notice that the text can contain HTML markup): Example Live Demo <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?> Display Variables The following example shows how to output text and variables with the echo statement: Example Live Demo <?php $var1 = "Learn PHP"; $var2 = "W3Schools.com"; $x = 5; $y = 4; echo "<h2>" . $var1 . "</h2>"; echo "Study PHP at " . $var2 . "<br>"; echo $x + $y; ?> The PHP print Statement The print statement can be used with or without parentheses: print or print(). Display Text The following example shows how to output text with the print command (notice that the textcontinue reading.

PHP – Constants Types

PHP constants are name or identifier that can't be changed at the time of the execution of the script. we used PHP constants in 2 ways: Using define() function Using const keyword PHP constants follow the same PHP variable rules. For example, it can be started with a letter or underscore only. Conventionally, PHP constants should be defined in uppercase letters. PHP constant: define() Let's see the syntax of define() function in PHP. define(name, value, case-insensitive)  name: specifies the constant name value: specifies the constant value case-insensitive: Default value is false. <?php define("MESSAGE","Hello JavaTpoint PHP"); echo MESSAGE; ?> Output: Hello JavaTpoint PHP Const Keyword The const keyword defines constants at compile time. It is a language construct not a function. It is a bit faster than define(). It is always case sensitive. <?php const MESSAGE="Hello const by JavaTpoint PHP"; echo MESSAGE; ?> Output: Hello const by JavaTpoint PHPcontinue reading.

PHP Data Types

PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types that can be categorized further in 3 types: Scalar Types Compound Types Special Types PHP Data Types: Scalar Types There are 4 scalar data types in PHP. boolean integer float string PHP Data Types: Compound Types There are 2 compound data types in PHP. array object PHP Data Types: Special Types There are 2 special data types in PHP. resource NULL

continue reading.

PHP Operators

PHP language has following types of operators. Arithmetic Operators Comparison Operators Logical/Relational Operators Assignment Operators Conditional/ternary Operators Arithmetic Operators Operator Description Example + Adds two operands A + B will give 30 – Subtracts second operand from the first A – B will give -10 * Multiply both operands A * B will give 200 / Divide numerator by de-numerator B / A will give 2 % Modulus Operator and the remainder of after an integer division B % A will give 0 ++ Increment operator, increases integer value by one A++ will give 11 — Decrement operator, decreases integer value by one A– will give 9 Comparison Operators Operator Description Example == Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the value of two operands are equal or not, if values are not equal then the condition becomes true. (A != B) is true. > Checks if the value of the left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of the left

continue reading.