0% found this document useful (0 votes)
71 views22 pages

PHP Programming: John Ryan B. Lorca Instructor I

This document discusses basic PHP programming concepts including PHP syntax, comments, variables, data types, operators, and control structures. It covers PHP tags, echo/print functions, commenting syntax, variable naming conventions, storing different data types in variables, concatenating and manipulating strings, basic math operations, floats, constants, if/else statements, while loops, for loops, and foreach loops. It provides examples of declaring variables, performing calculations, looping, and an exercise to demonstrate various concepts.

Uploaded by

Eric Nilo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views22 pages

PHP Programming: John Ryan B. Lorca Instructor I

This document discusses basic PHP programming concepts including PHP syntax, comments, variables, data types, operators, and control structures. It covers PHP tags, echo/print functions, commenting syntax, variable naming conventions, storing different data types in variables, concatenating and manipulating strings, basic math operations, floats, constants, if/else statements, while loops, for loops, and foreach loops. It provides examples of declaring variables, performing calculations, looping, and an exercise to demonstrate various concepts.

Uploaded by

Eric Nilo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

PHP Programming

John Ryan B. Lorca Instructor I

PHP Programming
<?php ?>

Short syntax

<?php phpinfo(); ?>

Echo/ Print function


echo

or & concatenation

Comments
It is good practice to enter comments
//single-line comments are like this #or like this /* Multiple line comments*/

Variables Names
In PHP variable starts with a $ Followed by letter or underscore Can contain letters, numbers, underscores, or dashes No spaces Case-sensitive are different as it is case sensitive

$student and $Student

Global variable global $student Superglobals Automatically available throughout all program $_GET $_POST $_Request $_COOKIES $_SESSION

Examples of Variable Names:


$employee $Employee $NicEmployee (camel case) $Nic_Employee $Nic-Employee (Not a good practice) $Employee3 $_employee (Not a good practice) $__employee (Not a good practice)
6

Storing strings and numbers in variables

Strings:

Strings concatenate:

Strings function:

10

Basic Math:

11

Float

12

Float

13

Boolean and Null

14

Constants

15

IF statement
If (expression)
Statement;

16

While Loop:
While (expression)
Statement;

17

Same example with for Loop:


For (Initial; expression; end)

18

Foreach Loop:

19

Continue:

20

Break:

21

EXERCISE
Declare a variable myInteger and set it to 69 Declare myFloat and set it to 12.5 Get the sum, difference, product, quotient of myInteger and myFloat; display results Declare a variable myString and assign Hello World to myString Concatenate and hello Philippines Display myStringDisplay your full name N times with numbering, where Nis your age Display all the numbers from 1 to 10
If the number is odd, display the number If the number is even, display Im happy today!
22

You might also like