0% found this document useful (0 votes)
16 views20 pages

Variables, Constant, Data Types

The document outlines a course on Web Technologies focusing on PHP, covering topics such as variables, constants, data types, and database connectivity. It includes course outcomes that emphasize understanding and analyzing PHP concepts, WordPress themes, and security issues. Additionally, it provides examples and references for further learning on PHP programming.

Uploaded by

siyalohiya67
Copyright
© © All Rights Reserved
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)
16 views20 pages

Variables, Constant, Data Types

The document outlines a course on Web Technologies focusing on PHP, covering topics such as variables, constants, data types, and database connectivity. It includes course outcomes that emphasize understanding and analyzing PHP concepts, WordPress themes, and security issues. Additionally, it provides examples and references for further learning on PHP programming.

Uploaded by

siyalohiya67
Copyright
© © All Rights Reserved
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
You are on page 1/ 20

UNIVERSITY INSTITUTE OF COMPUTING

Bachelor of Computer Application

Subject Name: Web Technologies


22CAH-371/23SCH-254

Web Technologies DISCOVER . LEARN . EMPOWER


1
Web Development
Using PHP
Course Outcome • OOP
CO Title Level
Number
• Session and Cookies
• File handling
CO1 Understand

Students will learn basics of PHP • Database


CO2 Understand
Students will understand the underlying concept of themes in & Analyze
wordpress.

CO3 Understand
Students will learn database connectivity, plugin and security
issues.

2
Web Technologies
• Web development
Course Outcome
CO Title Level
• History
Number • Static pages
CO1 Understand • Dynamic pages
Students will learn basics of PHP

CO2 Understand
Students will understand the underlying concept of themes in & Analyze
wordpress.

CO3 Understand
Students will learn database connectivity, plugin and security
issues.

3
Topic to be Covered

• Variables
• PHP Constants
• Data types

4
PHP Variables

• variable is declared using a $ sign followed by the variable name.


• PHP is a loosely typed language, so we do not need to declare the data types of the variables. It automatically analyzes the
values and makes conversions to its correct datatype .
• Syntax of declaring a variable in PHP is given below:
• $variablename=value;
• Rules for declaring PHP variable:
• A variable must start with a dollar ($) sign, followed by the variable name.
• It can only contain alpha-numeric character and underscore (A-z, 0-9, _).
• A variable name must start with a letter or underscore (_) character.
• A PHP variable name cannot contain spaces.
• One thing to be kept in mind that the variable name cannot start with a number or special symbols.

5
Declaring Variables

<?
php
$name = "John"; // String
$age = 25; // Integer
$isActive = true; // Boolean
$balance = 50.75; // Float
?>

6
Variable Scope

PHP variables can have different scopes:

Global: Declared outside any function or class and accessible


globally using the global keyword or $GLOBALS array.

Local: Declared within a function and accessible only inside that


function.

Static: Retains its value between function calls using the static
keyword.

7
PHP Constants
• PHP constants are name or identifier that can't be changed during
the execution of the script except for magic constants, which are not
really constants. PHP constants can be defined by 2 ways:
• Using define() function
• Using const keyword
• Constants are similar to the variable except once they defined, they
can never be undefined or changed. They remain constant across the
entire program. PHP constants follow the same PHP variable
rules. For example, it can be started with a letter or underscore only.

8
Constants
Let's see the example to define PHP constant using define().
File: constant1.php

1. <?php
2. define("MESSAGE","Hello JavaTpoint PHP");
3. echo MESSAGE;
4. ?>
Output:
Hello JavaTpoint PHP

9
Data Types
PHP data types are used to hold different types of data or values.
PHP supports 8 primitive data types that can be categorized
further in 3 types:

1. Scalar Types (predefined)


2. Compound Types (user-defined)
3. Special Types

10
Data types:

11
Data Types
PHP Data Types: Scalar Types
It holds only single value. There are 4 scalar data types in PHP.
1. boolean
2. integer
3. float
4. String
PHP Boolean
Booleans are the simplest data type works like switch. It holds only two values: TRUE
(1) or FALSE (0). It is often used with conditional statements. If the condition is correct, it
returns TRUE otherwise FALSE.
Example:
<?php
if (TRUE)
echo "This condition is TRUE.";
if (FALSE)
echo "This condition is FALSE.";
?>

12
Continue……

• PHP Integer
• Integer means numeric data with a negative or positive sign. It holds only whole numbers, i.e., numbers without
fractional part or decimal points.
<?php
$dec1 = 34;
$oct1 = 0243;
$hexa1 = 0x45;
echo "Decimal number: " .$dec1. "</br>";
echo "Octal number: " .$oct1. "</br>";
echo "HexaDecimal number: " .$hexa1. "</br>";
?>

13
Continue……..
PHP Float
• A floating-point number is a number with a decimal point. Unlike integer, it can hold numbers with a
fractional or decimal point, including a negative or positive sign.
• Example:<?php
$n1 = 19.34;
$n2 = 54.472;
$sum = $n1 + $n2;
echo "Addition of floating numbers: " .$sum; ?>
PHP String
• A string is a non-numeric data type. It holds letters or any alphabets, numbers, and even special characters.
• String values must be enclosed either within single quotes or in double quotes. But both are treated
differently.
• Example:
<?php $company = "Javatpoint";
//both single and double quote statements will treat different
echo "Hello $company";
echo "</br>";
echo 'Hello $company'; >
14
PHP Array & PHP objects.
• An array is a compound data type. It can store multiple values of same data type in a single variable.
Example:
<?php
$bikes = array ("Royal Enfield", "Yamaha", "KTM");
var_dump($bikes); //the var_dump() function returns the datatype and values
echo "</br>";
echo "Array Element1: $bikes[0] </br>";
echo "Array Element2: $bikes[1] </br>";
echo "Array Element3: $bikes[2] </br>";
?>
• Objects are the instances of user-defined classes that can store both values and functions. They must be
explicitly declared.Example:
<?php
class bike {
function model() {
$model_name = "Royal Enfield";
echo "Bike Model: " .$model_name;
} }
$obj = new bike();
$obj -> model();
15
?>
PHP Resource & PHP Null

• PHP Resource
• Resources are not the exact data type in PHP. Basically, these are used to store some function calls or references to
external PHP resources. For example - a database call. It is an external resource.
• This is an advanced topic of PHP, so we will discuss it later in detail with examples.
• PHP Null
• Null is a special data type that has only one value: NULL. There is a convention of writing it in capital letters as it is case
sensitive.
• Example:
<?php
$nl = NULL;
echo $nl; //it will not give any output
?>

16
Image References

[1] www.w3resource.com/w3r_images/class-and-object-of-class.gif

[3]www.expertphp.in/images/articles/

ArtImgC67UTd_classes_and_objects.jpg

17
Book References
• Php: The Complete Reference, Steven Holzner, Tata McGraw-
Hill Education, 2007
• Modern PHP: New Features and Good Practices, Josh Lockhart,
"O'Reilly Media, Inc.“, 2015.
• PHP for the Web: Visual QuickStart Guide, Larry Ullman
Pearson Education, 2006.
• https://www.tutorialspoint.com/php/index.htm
• https://www.codecademy.com/learn/learn-php

18
Video Links
• https://www.youtube.com/watch?v=yrIbbKuSqK8
• https://www.youtube.com/watch?v=GVGolpfz-ms

19
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy