Basic PHP


basic php

Basic PHP

Learn Basic PHP

This post will be short to understand basic php , lets clear something , PHP is scripting language it’s widely used in almost any dynamic website, the term “Dynamic Website” simply means , interactive website where users can register or send a form or even retrieve data from database. Like movie website

 

What you need to know before start learning PHP ?

1-HTML

2-CSS

3-Basic Javascript

The simple Code of PHP :

<!DOCTYPE html>
<html>
<body>

<?php
echo “My first PHP script!”;
?>

</body>
</html>

 

PHP code can be inserted inside html page by ” <?php ”  and closing ” < ?> ” .

We use ” echo ” to print anything , that can be regular html tags or php variables .

 

What PHP consist of :

1-Variables

2-Function

3-Loops

4-Arrays

5- Conditions

6-Switch Statement

And there are more, like sessions ,cookies and Files , but we going to talk about it in future post.

 

Variables 

Definition : In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Typically, a program consists of instruction s that tell the computer what to do and data that the program uses when it is running. The data consists of constants or fixed values that never change and variable values (which are usually initialized to “0” or some default value because the actual values will be supplied by a program’s user). Usually, both constants and variables are defined as certain data type s. Each data type prescribes and limits the form of the data. Examples of data types include: an integer expressed as a decimal number, or a string of text characters, usually limited in length.

 

There are :

Integer      (123456789 )   Exm: $var = 15;

String        (Text , should be written between double quot “my text “)     $txt = ” Hello World ” ;

Boolean    (True or False )     $conditon = true;

Note: PHP is loosely typed language, That means you don’t have to declare which type of variable before you use it, like in other programming languages such as Java or C++.

Example :

<?php 

$myname  = “Akram”;

$age = 26;

echo “my name is ”   .    $myname   .     ” Age  ” .    $age;

?>

Notice : for concatenation use dot .

 

Functions 

Function is block of code that perform certain actions whenever we call it.

to define a function this is the syntax :

function functionName(   ) {
    code to be executed;
}

 

 

 

 

 

 

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz