Category Archives: Learn and Start PHP - Page 2

php – operators

An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value (so that the construction itself becomes an expression).Operators are used to manipulate or perform operations on variables and values.

There are many operators used in PHP.

1. Comparison Operator

2. Increment/Decrement Operator

3. Logical Operator

4. Arithmatic Operator

Defining constants with example

Defn:

Constants are those whose value remains the same in executing environment.
How to define constants with example:

<?php
define("PI", 3.1415); //Defining a constant called PI
$r=5; //r for radius
$area = PI*$r*$r; //area calculation of circle
Echo "Areas of circle with radius $r is ".$area.".";
?>

PHP variable and its Declaration

some of you are wondering what is variable…ok if you need to store water what do you need ..simply glass ..bucket something that can store water ya.
Ok this is variable… the something(memory ) ..bucket that can store some value for further use …variable is nothing more than this.

Than how to use variable:
<?php
$message = “www.phpfresher.com”;
echo $message;
?>
Check out this  exercise and try yourself:

<?php
$qty = 5;
$price = 10000;
$amt = $qty*$price;
echo “Rs. “.number_format($amt, 2);
?>
Note: PHP variable is declared with the dollar($) sign at the start.

How to embed php with HTML tags:

1. In the body section just type :-<?php echo ‘This is our first php class’;?>
2. Run your project.

Did you find what the echo does. It displays the string in the browser as output.

How to echo html codes in .php file :

Here goes the code:
<?php
echo ‘<table><tr><td>name</td></tr></table>’;
?>
This code displays the table through php code.But don’t get confused you can do this directly in the .php file directly without embedding in <?php ?> tag. As you used to do in HTML. Why I have  shown this example is in future you may need to echo some html elements through php so don’t get confused.

How to run your project

After you have successfully finished the folder configuration .Now its turn to run your file/project. Ok here is description.

1.open the browser
2. Type localhost/your_project_folder(Remember: when you do this the default page that will run Is index.php). So make sure if you have only one page e.g. service.php make sure to type localhost/your_project_folder/file_name.php(service.php).