PHP First LCTR DR - RMT
PHP First LCTR DR - RMT
1. Introduction To PHP
3. PHP Operators
5. PHP Arrays
6. PHP Loops
7. PHP Functions
[12/17, 6:24 AM] Al AMEEN CYPRUS: To run php in your computer you will need to download XAMPP for
windows, Linux or even for IOS operating systems, just specify any you wish. After downloading you will
have to install it in your computer and run it. You will have to enable the following as they appear in
image below; make sure it indicates running,
Then you will have to download any of the text editor either, notepad++, brackets, visual studio code,
sublime text, among others.
[12/17, 6:24 AM] Al AMEEN CYPRUS: Let start with the introduction
[12/17, 6:24 AM] Al AMEEN CYPRUS: After you install your text editor you will go to the search label in
your computer and search for xampp htdocs then open that folder then create a new folder you may
name it as, “myproject”, then drag and drop it in your text editor.
[12/17, 6:24 AM] Al AMEEN CYPRUS: Open it and delete all the content Inside
[12/17, 6:25 AM] Al AMEEN CYPRUS: Create a new folder with name myproject
[12/17, 6:25 AM] Al AMEEN CYPRUS: Om open the folder and create a file with name index.php
[12/17, 6:25 AM] Al AMEEN CYPRUS: Browse and Save the empty file at htdocs inside myproject folder
with 11.php
[12/17, 6:25 AM] Al AMEEN CYPRUS: Ok open the browser on new tab and type this
[12/17, 6:25 AM] Al AMEEN CYPRUS: 11.php should be name of the file
[12/17, 6:25 AM] Al AMEEN CYPRUS: Good this is how to create a file
[12/17, 6:25 AM] Al AMEEN CYPRUS: Ok try and create as many files as you can
[12/17, 6:25 AM] Al AMEEN CYPRUS: We will start the coding tomorrow
[12/17, 6:25 AM] Al AMEEN CYPRUS: Will you mind if I give you lecture now?
[12/17, 6:25 AM] Al AMEEN CYPRUS: *Basic Tags In Php Programming Language*
[12/17, 6:25 AM] Al AMEEN CYPRUS: *1.* First you will need to type the following codes in your html
program in between body tags as;
[12/17, 6:25 AM] Al AMEEN CYPRUS: Open a php.11 and type html it will complete the rest of the tag for
you
[12/17, 6:25 AM] Al AMEEN CYPRUS: Here is the code
[12/17, 6:25 AM] Al AMEEN CYPRUS: *Note* every php program start with <?php as open tag and end
with. ?>
<html>
<head>
</head>
<body>
<?php
?>
</body>
</html>
[12/17, 6:25 AM] Al AMEEN CYPRUS: Let me see when you're done
[12/17, 6:25 AM] Al AMEEN CYPRUS: After you type those codes you can now go ahead and start your
programming using php language, for instance.
[12/17, 6:25 AM] Al AMEEN CYPRUS: Every time your using php make sure your xampp is on
[12/17, 6:25 AM] Al AMEEN CYPRUS: Now, replace your name with this <?php
php info();
?>
[12/17, 6:25 AM] Al AMEEN CYPRUS: Every time your running php
[12/17, 6:25 AM] Al AMEEN CYPRUS: Just type localhost on your browser
[12/17, 6:25 AM] Al AMEEN CYPRUS: To that case it will produce all information about php installed into
that computer
[12/17, 6:25 AM] Al AMEEN CYPRUS: Try and practice this before I come back from meeting
[12/17, 6:25 AM] Al AMEEN CYPRUS: You can change the hello world with anything you like
[12/17, 6:25 AM] Al AMEEN CYPRUS: Let’s now look at the variables- is a symbol or name that stands for
a value, for example to use variables you will type the following in between php tags.
$school="schoolname".
[12/17, 6:25 AM] Al AMEEN CYPRUS: I want you to follow this format and declare a variable with your
details
1. Name
2. School
3. Department
4. Course
And others
[12/17, 6:25 AM] Al AMEEN CYPRUS: But first declare the variable before you echo them
[12/17, 6:25 AM] Al AMEEN CYPRUS: After then you use echo to print them
[12/17, 6:25 AM] Al AMEEN CYPRUS: To add comment in php program you will have to use, // forward
slashes or # before your content as // echo “hello world”; the text will appear as a comment. But if you
wish to enclose a certain text you will type this; /* your content */ all content between those signs will
appear as a comment.
[12/17, 6:25 AM] Al AMEEN CYPRUS: Variables always starts with a letter A-z or underscore (_) then
followed by other letters or numbers. For instance, $9name is not valid but this $_9name is valid.
<?php
$cars=array("BMW","AUDI","MERCEDEZ");
echo $cars[1];
?>
First we do you ask yourself what an array? Array– is a data structure that contains a group of elements,
typically these elements are all of the same data type, such as an integer or a string, arrays are
commonly used in computer programs to organize data so that a related set of values can be easily
sorted or searched. Then you start numbering your arrays from zero (0) and then numbering continues.
As the name suggests you associate your arrays with their values for instanceare you may associate a
certain car with its average speed it moves with. You associate arrays with use of this sigh equal or
greater than(=>) For example;
echo $cars[3]?
[12/17, 6:25 AM] Al AMEEN CYPRUS: *MULTIDIMENSIONAL ARRAYS*
As the name suggests this type of makes one use multiple arrays in the same program code, for
instance,
$cars=array("Audi"=>40.25,"BMW"=>34.78,"Mercedes"=>50.75);
//to output the average speed for Mercedes you will type this
echo $cars["Mercedes"];
?>
echo $cras["expensive"][1];
?>
It will output
Mercedes
You may using other values and see the results for better understanding
[12/17, 6:25 AM] Al AMEEN CYPRUS: *Use Of Operators In PHP Programming Language*
[12/17, 6:25 AM] Al AMEEN CYPRUS: In our last lecture we discussed use of arrays in php programming
language; now we are going deeper into php programming language as we will be discussing very basic
part of it which is various types of operators used.
[12/17, 6:25 AM] Al AMEEN CYPRUS: each programming language there is use of operators which are
categorized as below;
[12/17, 6:25 AM] Al AMEEN CYPRUS: We will now discuss each in detail;
*Arithmetic operators*
addition (+)
subtraction (-)
multiplication (*)
division (/)
percentage (%)
[12/17, 6:25 AM] Al AMEEN CYPRUS: for instance, a syntax for arithmetic operators; remember the
codes should be written in between php tags,
<?php
$x=5;
$y=6;
$total=$x+$y;
echo $total
?>
</body>
It will produce 11
You may use different operator and variable and try it yourself
[12/17, 6:25 AM] Al AMEEN CYPRUS: For instance, let’s have a syntax for a comparison operator,
<body>
<?php
$x=10;
$y=7;
if($x>&y){
}else{
?>
</body>
These operators are used to compare different variables as per the condition; they include;
Equal (==)
<?php
$x=5;
$y=6;
echo $x-=$y;
?>
</body>
It will produce -1
You may use different variables and operator and try it yourself
They include;
Pre-increment (++$x)
Post-increment ($x++)
Pre-decrement (–$x)
Post-decrement ($x–)
[12/17, 6:25 AM] Al AMEEN CYPRUS: For instance, let’s have a syntax for logical operators,
<body>
<?php
$x10;
echo $x-;
echo "<br>";
echo $x;
?>
</body>
It will produce 9
You may use different operator and variable and try it yourself.
1. Create two variables(x,y) add them ad multiply answer by 6. Print your answer as a variable ‘z’.
2. Define two variables(name,age) and print out in form of a statement telling us your name and age.
4. Create two variables(price,vat). Create a new variable ‘totalPrice’ then calculate the vat on the price
and print out the(vat,price,total Price).