PHP is a server-side scripting language means you need a web server, upload your script there and then call from the client (web browser) and you get the output in HTML or any other format whatever you want like JSON.
It is used to create dynamic and interactive websites.
<?php echo "Hello World"; ?>
This is hello world script of PHP. You can see that code is written in a tags <?php ?>. echo is a basic PHP statement to display output and each statement should end with a semicolon.
PHP Variables & Datatypes
- Variable use to store data in memory at runtime.
- PHP variables start with a dollar sign ($) followed by alphanumeric name begin with letter or underscore. example: $a or $_a.
- Variable names are case sensitive.
- PHP support boolean, integer, string, array, object, resource, and NULL.
<?php $hello = TRUE; $name = "sunil"; $salary = 10000; echo $name. " salary is ". $salary; ?>
Statements and Expressions
Here are some examples of statement and expressions
$a = 5; // assignment statement $b = 10; // assignment statement $name = "Sunil"; $buy = ($b > 10) ? "coffee" : "tea" // ternary conditional echo $name." buy " . $buy;
echo and print statement print one or more strings.
PHP supports arithmetic, comparison, and logical operators and it also supports like assignment, increment/decrement, string, and array operators. In PHP 7 conditional assignment operator is also added.
Arithmetic Operators like +, -, *, /,