SlideShare a Scribd company logo
 jQuery is a lightweight, "write less, do more", JavaScript library.
 The purpose of jQuery is to make it much easier to use JavaScript on your website.
 jQuery takes a lot of common tasks that require many lines of JavaScript code to
accomplish, and wraps them into methods that you can call with a single line of code.
 jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls
and DOM manipulation.
 The jQuery library contains the following features:
 HTML/DOM manipulation
 CSS manipulation
 HTML event methods
 Effects and animations
 AJAX
jQuery
jQuery Applications
There are lots of other JavaScript libraries out there, but jQuery is
probably the most popular, and also the most extendable.
Many of the biggest companies on the Web use jQuery, such as:
• Google
• Microsoft
• IBM
• Netflix
Adding jQuery to Your Web Pages
There are several ways to start using jQuery on your web site. You can:
 Download the jQuery library from jQuery.com
 Include jQuery from a CDN (Content Delivery Network)
Versions of jQuery
There are two versions of jQuery available for downloading:
Production version - this is for your live website because it has been minified and
compressed
Development version - this is for testing and development (uncompressed and readable
code
There are two ways of including jquery, either from google or microsoft.
Google CDN (Content Delivery Network)
<head> <script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></
script>
</head>
Microsoft CDN (Content Delivery Network)
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js">
</script>
</head>
Adding jQuery to your website
The main methods for manipulating HTML content in jQuery are:
 html(): Sets or returns the content of selected elements
 $("selector").html() returns the HTML content of the first
matched element
 $("selector").html("new content") sets the HTML content of the
matched elements
 $("selector").html(function(index, currentcontent)) sets the
content using a function
 text(): Sets or returns the text content of selected elements
Manipulating HTML Content
EXAMPLE
// Set the content of an element
$("h2").html("Hello <b>World!</b>");
// Return the content of the first matched element
alert($("h2").html());
// Set content using a function
$("h2").html(function(n))
{
return "jQuery | html() Method" + " has index: " + n;
});
ADDING AND REMOVING CLASSES
 addClass(): Adds one or more class names to selected elements
 removeClass(): Removes one or more classes from selected elements
 toggleClass(): Toggles between adding/removing one or more classes from selected elements
// Add a class
$("a").addClass("bold");
// Remove a class
$("a").removeClass("bold");
Inserting and Replacing Content
jQuery provides several methods for inserting and replacing
HTML content:
append(): Inserts content at the end of selected elements
prepend(): Inserts content at the beginning of selected
elements
after(): Inserts content after selected elements
before(): Inserts content before selected elements
replaceWith(): Replaces selected elements with new content
// Append content
$("div").append("<p>Appended text</p>");
// Prepend content
$("div").prepend("<p>Prepended text</p>");
// Insert after
$("div").after("<p>Inserted after</p>");
// Replace with
$("div").replaceWith("<p>Replaced div</p>");
Example
PHP
PHP, which stands for "PHP: Hypertext Preprocessor," is a widely-used
open-source server-side scripting language primarily designed for web
development.
Server-Side Execution: PHP scripts are executed on the server, generating
HTML that is sent to the client's browser. This allows for dynamic content
generation based on user input or other variables.
Integration with HTML: PHP can be easily embedded within HTML code,
allowing developers to mix PHP and HTML seamlessly. This makes it easier
to create dynamic web pages.
Database Support: PHP has built-in support for various databases such as
MySQL, PostgreSQL, and SQLite, enabling developers to create data-driven
applications.
Cross-Platform Compatibility: PHP runs on various operating systems,
including Windows, Linux, and macOS, making it versatile for different
server environments.
Open Source: Being open-source means PHP is free to use, and it has a
large community of developers contributing to its continuous improvement
and extensive documentation.
Dynamic Web Pages: PHP is primarily used to create dynamic web
pages that can respond to user inputs and display different content
based on various conditions.
Form Handling: PHP can collect and process form data, making it
essential for applications that require user interaction.
Session Management: PHP can manage user sessions, allowing for
personalized experiences on websites.
File Handling: PHP can create, read, write, and delete files on the
server, facilitating various functionalities like file uploads and
downloads.
Uses of PHP
Basic Syntax
A typical PHP file has a .php extension and can contain HTML, CSS, JavaScript,
and PHP code. The basic syntax for embedding PHP in an HTML document is
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<?php echo "Hello, World! This is PHP code.";?>
</body>
</html>
VARIABLES, CONSTANTS, DATA TYPES, AND ARRAYS IN PHP
 Variables
A variable in PHP is a container for storing data. It is defined by a
name that starts with a dollar sign ($), followed by the variable name.
PHP automatically assigns a data type to a variable based on the
value assigned to it.
 Rules for Naming Variables
Must start with a dollar sign ($).
Followed by a letter or an underscore, and can contain letters,
numbers, and underscores.
Variable names are case-sensitive (e.g., $myVar and $myvar are
different).
EXAMPL
E
$age = 25; // Integer
$name = "John"; // String
$height = 5.9; // Float
$isStudent = true; // Boolean
CONSTANTS
• Constants are similar to variables but are immutable; once
defined, their value cannot change during the execution of the
script.
• Constants are defined using the define() function or the const
keyword, and they do not require a dollar sign.
define("PI", 3.14); // Using define()
const GRAVITY = 9.81; // Using const
DATA TYPES
PHP Supports several data types, which can be categorized into simple, compound, and
special data types:
1.Simple Data Types
 Integer: Whole numbers, e.g., 42, -7.
 Float: Decimal numbers, e.g., 3.14, -0.001.
 String: Sequence of characters, e.g., "Hello, World!".
 Boolean: Represents two states, true or false.
2.Compound Data Types
 Array: A collection of values, which can be of mixed types.
 Object: An instance of a class.
3.Special Data Types
 NULL: Represents a variable with no value.
 Resource: A special variable that holds a reference to an external
resource, like a database connection.
EXAMPLE OF DATA
TYPES
$integerVar = 10; // Integer
$floatVar = 10.5; // Float
$stringVar = "Hello"; // String
$boolVar = true; // Boolean
$arrayVar = array(1, 2, 3); // Array
$nullVar = null; // NULL
ARRAYS
Arrays in PHP can store multiple values in a single variable. They can be indexed
(numerical) or associative (key-value pairs).
$colors = array("Red", "Green", "Blue");
echo $colors[0]; // Outputs: Red
$person = array("name" => "John", "age" => 30);
echo $person["name"]; // Outputs: John
Associative Array
Indexed Array
SETTING UP CONDITIONS IN PHP
SCRIPTS
Conditional statements are essential for controlling the flow of execution in PHP scripts. They
allow you to execute different blocks of code based on specific conditions. PHP provides several
conditional constructs to handle various scenarios:
if Statement
The if statement is the most basic conditional construct. It executes a
block of code if a specified condition is true.
$age = 18;
if ($age >= 18) {
echo "You are an adult.";
}
IF...ELSE STATEMENT
The if...else statement executes a block of code if a condition is true, and
another block if the condition is false.
$temperature = 25;
if ($temperature > 30)
{
echo "It's hot outside.";
}
else
{
echo "The weather is pleasant.";
}
IF...ELSEIF...ELSE STATEMENT
$grade = 85;
if ($grade >= 90)
{
echo "You got an A.";
} elseif ($grade >= 80)
{
echo "You got a B.";
} else
{
echo "You need to improve.";
}
The if...elseif...else statement executes different blocks of code based on
multiple conditions.
NESTED IF STATEMENTS
$age = 25;
$gender = "female";
if ($age >= 18) {
if ($gender == "female") {
echo "You are an adult female.";
} else {
echo "You are an adult male.";
}
}
nest if statements inside other if statements to create more complex
conditional logic.
SWITCH STATEMENT
The switch statement is an alternative to multiple if...elseif statements. It
executes different blocks of code based on different cases.
$day = 3;
switch ($day) {
case 1:
echo "Monday";
break;
case 2:
echo "Tuesday";
break;
case 3:
echo "Wednesday";
break;
default:
echo "Invalid day";
}
REPEATING ACTIONS WITH LOOP IN PHP
 Loops in PHP allow you to repeatedly execute a block of code until a
certain condition is met.
 This is useful when you need to perform an action multiple times or
iterate over a collection of data.
 PHP provides several types of loops
 for Loop
 while Loop
 do...while Loop
 foreach Loop
for Loop
The for loop is used when you know in advance how many times the loop
should execute. It consists of three parts separated by semicolons:
initialization, condition, and increment/decrement.
for ($i = 1; $i <= 5; $i++)
{
echo "Iteration $i<br>";
}
Output
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
while Loop
The while loop continues to execute a block of code as long as a
specified condition is true.
$count = 1;
while ($count <= 3) {
echo "Count: $count<br>";
$count++;
}
Output
Count: 1
Count: 2
Count: 3
do...while Loop
The do...while loop is similar to the while loop, but it guarantees that the
code block is executed at least once before the condition is tested.
$i = 1;
do {
echo "Value of i: $i<br>";
$i++;
} while ($i <= 5);
Output
Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5
foreach Loop
The foreach loop is specifically designed for iterating over arrays and objects. It
automatically assigns each value of the array to a variable.
$fruits = array("apple", "banana", "cherry");
foreach ($fruits as $fruit) {
echo "I like $fruit<br>";
}
Output
I like apple
I like banana
I like cherry
USING FUNCTIONS IN PHP
Functions in PHP are blocks of code designed to perform specific
tasks.
They enhance code reusability, maintainability, and
organization.
PHP supports two main types of functions: built-in functions
and user-defined functions.
 PHP comes with a vast library of built-in functions, which are
pre-defined and ready to use. These functions cover a wide range
of tasks, including string manipulation, mathematical
calculations, and file handling.
Examples
 strlen(): Returns the length of a string.
 array_push(): Adds one or more elements to the end of an array.
 var_dump(): Displays structured information about one or more
variables.
Built-in Functions
USER-DEFINED FUNCTIONS
User-defined functions allow you to create your own functions tailored to
your specific needs.
function
functionName($parameter1,
$parameter2) {
// code to be executed
}
function sample($name) {
echo "Hello, $name!";
}
// Calling the function
sample("Abc");
Syntax Example
FUNCTION PARAMETERS
Functions can accept parameters, which are variables passed into the
function. You can define multiple parameters, separated by commas.
function add($a, $b)
{
return $a + $b;
}
$result = add(5, 10);
echo "The sum is: $result"; // Outputs: The sum is: 15
DEFAULT PARAMETER VALUES
You can set default values for parameters. If a value is not
provided during the function call, the default value will be used.
function greet($name = "Guest")
{
echo "Hello, $name!";
}
greet(); // Outputs: Hello, Guest!
greet("Bob"); // Outputs: Hello, Bob!
RETURNING VALUES
Functions can return values using the return statement. Once a return
statement is executed, the function stops executing.
function square($number)
{
return $number * $number;
}
echo "The square of 4 is: " . square(4); // Outputs: The square of 4 is: 16
CALL BY VALUE VS. CALL BY REFERENCE
By default, PHP passes arguments to functions by value, meaning a copy of the variable is
passed. If you want to pass a variable by reference (allowing the function to modify the
original variable), you can use the & symbol.
function increment(&$value)
{
$value++;
}
$num = 5;
increment($num);
echo $num; // Outputs: 6

More Related Content

Similar to Jquery in web development, including Jquery in HTML (20)

PDF
Introduction of PHP.pdf
karinaabyys
 
PPTX
Php Unit 1
team11vgnt
 
PPSX
PHP Comprehensive Overview
Mohamed Loey
 
PPT
Synapseindia reviews on array php
saritasingh19866
 
PPT
Prersentation
Ashwin Deora
 
PDF
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PDF
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PPT
Php mysql
Ajit Yadav
 
PPT
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
PDF
WT_PHP_PART1.pdf
HambardeAtharva
 
PPT
Intro to PHP for Students and professionals
cuyak
 
PPT
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
PPT
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
PPT
Php introduction
Osama Ghandour Geris
 
PPTX
introduction to php and its uses in daily
vishal choudhary
 
PDF
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PPTX
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
PPT
05php
Shahid Usman
 
PPT
Introduction to php php++
Tanay Kishore Mishra
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
Introduction of PHP.pdf
karinaabyys
 
Php Unit 1
team11vgnt
 
PHP Comprehensive Overview
Mohamed Loey
 
Synapseindia reviews on array php
saritasingh19866
 
Prersentation
Ashwin Deora
 
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Php mysql
Ajit Yadav
 
PHP and MySQL.ppt
ROGELIOVILLARUBIA
 
WT_PHP_PART1.pdf
HambardeAtharva
 
Intro to PHP for Students and professionals
cuyak
 
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
Php introduction
Osama Ghandour Geris
 
introduction to php and its uses in daily
vishal choudhary
 
Wt unit 4 server side technology-2
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Web Application Development using PHP Chapter 1
Mohd Harris Ahmad Jaal
 
Introduction to php php++
Tanay Kishore Mishra
 
PHP Hypertext Preprocessor
adeel990
 

More from backiyalakshmi14 (9)

PPTX
Introduction to database management system
backiyalakshmi14
 
PPTX
Normalization in Relational database management systems
backiyalakshmi14
 
PPT
Memory Management techniques in operating systems
backiyalakshmi14
 
PPTX
sequential circuits, flip flops and Latches
backiyalakshmi14
 
PPTX
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
backiyalakshmi14
 
PPTX
Half adders and full adders in digital principles
backiyalakshmi14
 
PPTX
Basic gates in electronics and digital Principles
backiyalakshmi14
 
PPTX
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
PPTX
HUMAN VALUES DEVELOPMENT for skill development
backiyalakshmi14
 
Introduction to database management system
backiyalakshmi14
 
Normalization in Relational database management systems
backiyalakshmi14
 
Memory Management techniques in operating systems
backiyalakshmi14
 
sequential circuits, flip flops and Latches
backiyalakshmi14
 
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
backiyalakshmi14
 
Half adders and full adders in digital principles
backiyalakshmi14
 
Basic gates in electronics and digital Principles
backiyalakshmi14
 
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
HUMAN VALUES DEVELOPMENT for skill development
backiyalakshmi14
 
Ad

Recently uploaded (20)

PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPT
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
epi editorial commitee meeting presentation
MIPLM
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
infertility, types,causes, impact, and management
Ritu480198
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
Controller Request and Response in Odoo18
Celine George
 
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Ad

Jquery in web development, including Jquery in HTML

  • 1.  jQuery is a lightweight, "write less, do more", JavaScript library.  The purpose of jQuery is to make it much easier to use JavaScript on your website.  jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.  jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.  The jQuery library contains the following features:  HTML/DOM manipulation  CSS manipulation  HTML event methods  Effects and animations  AJAX jQuery
  • 2. jQuery Applications There are lots of other JavaScript libraries out there, but jQuery is probably the most popular, and also the most extendable. Many of the biggest companies on the Web use jQuery, such as: • Google • Microsoft • IBM • Netflix
  • 3. Adding jQuery to Your Web Pages There are several ways to start using jQuery on your web site. You can:  Download the jQuery library from jQuery.com  Include jQuery from a CDN (Content Delivery Network) Versions of jQuery There are two versions of jQuery available for downloading: Production version - this is for your live website because it has been minified and compressed Development version - this is for testing and development (uncompressed and readable code
  • 4. There are two ways of including jquery, either from google or microsoft. Google CDN (Content Delivery Network) <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></ script> </head> Microsoft CDN (Content Delivery Network) <head> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"> </script> </head> Adding jQuery to your website
  • 5. The main methods for manipulating HTML content in jQuery are:  html(): Sets or returns the content of selected elements  $("selector").html() returns the HTML content of the first matched element  $("selector").html("new content") sets the HTML content of the matched elements  $("selector").html(function(index, currentcontent)) sets the content using a function  text(): Sets or returns the text content of selected elements Manipulating HTML Content
  • 6. EXAMPLE // Set the content of an element $("h2").html("Hello <b>World!</b>"); // Return the content of the first matched element alert($("h2").html()); // Set content using a function $("h2").html(function(n)) { return "jQuery | html() Method" + " has index: " + n; });
  • 7. ADDING AND REMOVING CLASSES  addClass(): Adds one or more class names to selected elements  removeClass(): Removes one or more classes from selected elements  toggleClass(): Toggles between adding/removing one or more classes from selected elements // Add a class $("a").addClass("bold"); // Remove a class $("a").removeClass("bold");
  • 8. Inserting and Replacing Content jQuery provides several methods for inserting and replacing HTML content: append(): Inserts content at the end of selected elements prepend(): Inserts content at the beginning of selected elements after(): Inserts content after selected elements before(): Inserts content before selected elements replaceWith(): Replaces selected elements with new content
  • 9. // Append content $("div").append("<p>Appended text</p>"); // Prepend content $("div").prepend("<p>Prepended text</p>"); // Insert after $("div").after("<p>Inserted after</p>"); // Replace with $("div").replaceWith("<p>Replaced div</p>"); Example
  • 10. PHP PHP, which stands for "PHP: Hypertext Preprocessor," is a widely-used open-source server-side scripting language primarily designed for web development. Server-Side Execution: PHP scripts are executed on the server, generating HTML that is sent to the client's browser. This allows for dynamic content generation based on user input or other variables. Integration with HTML: PHP can be easily embedded within HTML code, allowing developers to mix PHP and HTML seamlessly. This makes it easier to create dynamic web pages. Database Support: PHP has built-in support for various databases such as MySQL, PostgreSQL, and SQLite, enabling developers to create data-driven applications. Cross-Platform Compatibility: PHP runs on various operating systems, including Windows, Linux, and macOS, making it versatile for different server environments. Open Source: Being open-source means PHP is free to use, and it has a large community of developers contributing to its continuous improvement and extensive documentation.
  • 11. Dynamic Web Pages: PHP is primarily used to create dynamic web pages that can respond to user inputs and display different content based on various conditions. Form Handling: PHP can collect and process form data, making it essential for applications that require user interaction. Session Management: PHP can manage user sessions, allowing for personalized experiences on websites. File Handling: PHP can create, read, write, and delete files on the server, facilitating various functionalities like file uploads and downloads. Uses of PHP
  • 12. Basic Syntax A typical PHP file has a .php extension and can contain HTML, CSS, JavaScript, and PHP code. The basic syntax for embedding PHP in an HTML document is <html> <head> <title>PHP Example</title> </head> <body> <?php echo "Hello, World! This is PHP code.";?> </body> </html>
  • 13. VARIABLES, CONSTANTS, DATA TYPES, AND ARRAYS IN PHP  Variables A variable in PHP is a container for storing data. It is defined by a name that starts with a dollar sign ($), followed by the variable name. PHP automatically assigns a data type to a variable based on the value assigned to it.  Rules for Naming Variables Must start with a dollar sign ($). Followed by a letter or an underscore, and can contain letters, numbers, and underscores. Variable names are case-sensitive (e.g., $myVar and $myvar are different).
  • 14. EXAMPL E $age = 25; // Integer $name = "John"; // String $height = 5.9; // Float $isStudent = true; // Boolean
  • 15. CONSTANTS • Constants are similar to variables but are immutable; once defined, their value cannot change during the execution of the script. • Constants are defined using the define() function or the const keyword, and they do not require a dollar sign. define("PI", 3.14); // Using define() const GRAVITY = 9.81; // Using const
  • 16. DATA TYPES PHP Supports several data types, which can be categorized into simple, compound, and special data types: 1.Simple Data Types  Integer: Whole numbers, e.g., 42, -7.  Float: Decimal numbers, e.g., 3.14, -0.001.  String: Sequence of characters, e.g., "Hello, World!".  Boolean: Represents two states, true or false. 2.Compound Data Types  Array: A collection of values, which can be of mixed types.  Object: An instance of a class. 3.Special Data Types  NULL: Represents a variable with no value.  Resource: A special variable that holds a reference to an external resource, like a database connection.
  • 17. EXAMPLE OF DATA TYPES $integerVar = 10; // Integer $floatVar = 10.5; // Float $stringVar = "Hello"; // String $boolVar = true; // Boolean $arrayVar = array(1, 2, 3); // Array $nullVar = null; // NULL
  • 18. ARRAYS Arrays in PHP can store multiple values in a single variable. They can be indexed (numerical) or associative (key-value pairs). $colors = array("Red", "Green", "Blue"); echo $colors[0]; // Outputs: Red $person = array("name" => "John", "age" => 30); echo $person["name"]; // Outputs: John Associative Array Indexed Array
  • 19. SETTING UP CONDITIONS IN PHP SCRIPTS Conditional statements are essential for controlling the flow of execution in PHP scripts. They allow you to execute different blocks of code based on specific conditions. PHP provides several conditional constructs to handle various scenarios: if Statement The if statement is the most basic conditional construct. It executes a block of code if a specified condition is true. $age = 18; if ($age >= 18) { echo "You are an adult."; }
  • 20. IF...ELSE STATEMENT The if...else statement executes a block of code if a condition is true, and another block if the condition is false. $temperature = 25; if ($temperature > 30) { echo "It's hot outside."; } else { echo "The weather is pleasant."; }
  • 21. IF...ELSEIF...ELSE STATEMENT $grade = 85; if ($grade >= 90) { echo "You got an A."; } elseif ($grade >= 80) { echo "You got a B."; } else { echo "You need to improve."; } The if...elseif...else statement executes different blocks of code based on multiple conditions.
  • 22. NESTED IF STATEMENTS $age = 25; $gender = "female"; if ($age >= 18) { if ($gender == "female") { echo "You are an adult female."; } else { echo "You are an adult male."; } } nest if statements inside other if statements to create more complex conditional logic.
  • 23. SWITCH STATEMENT The switch statement is an alternative to multiple if...elseif statements. It executes different blocks of code based on different cases. $day = 3; switch ($day) { case 1: echo "Monday"; break; case 2: echo "Tuesday"; break; case 3: echo "Wednesday"; break; default: echo "Invalid day"; }
  • 24. REPEATING ACTIONS WITH LOOP IN PHP  Loops in PHP allow you to repeatedly execute a block of code until a certain condition is met.  This is useful when you need to perform an action multiple times or iterate over a collection of data.  PHP provides several types of loops  for Loop  while Loop  do...while Loop  foreach Loop
  • 25. for Loop The for loop is used when you know in advance how many times the loop should execute. It consists of three parts separated by semicolons: initialization, condition, and increment/decrement. for ($i = 1; $i <= 5; $i++) { echo "Iteration $i<br>"; } Output Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5
  • 26. while Loop The while loop continues to execute a block of code as long as a specified condition is true. $count = 1; while ($count <= 3) { echo "Count: $count<br>"; $count++; } Output Count: 1 Count: 2 Count: 3
  • 27. do...while Loop The do...while loop is similar to the while loop, but it guarantees that the code block is executed at least once before the condition is tested. $i = 1; do { echo "Value of i: $i<br>"; $i++; } while ($i <= 5); Output Value of i: 1 Value of i: 2 Value of i: 3 Value of i: 4 Value of i: 5
  • 28. foreach Loop The foreach loop is specifically designed for iterating over arrays and objects. It automatically assigns each value of the array to a variable. $fruits = array("apple", "banana", "cherry"); foreach ($fruits as $fruit) { echo "I like $fruit<br>"; } Output I like apple I like banana I like cherry
  • 29. USING FUNCTIONS IN PHP Functions in PHP are blocks of code designed to perform specific tasks. They enhance code reusability, maintainability, and organization. PHP supports two main types of functions: built-in functions and user-defined functions.
  • 30.  PHP comes with a vast library of built-in functions, which are pre-defined and ready to use. These functions cover a wide range of tasks, including string manipulation, mathematical calculations, and file handling. Examples  strlen(): Returns the length of a string.  array_push(): Adds one or more elements to the end of an array.  var_dump(): Displays structured information about one or more variables. Built-in Functions
  • 31. USER-DEFINED FUNCTIONS User-defined functions allow you to create your own functions tailored to your specific needs. function functionName($parameter1, $parameter2) { // code to be executed } function sample($name) { echo "Hello, $name!"; } // Calling the function sample("Abc"); Syntax Example
  • 32. FUNCTION PARAMETERS Functions can accept parameters, which are variables passed into the function. You can define multiple parameters, separated by commas. function add($a, $b) { return $a + $b; } $result = add(5, 10); echo "The sum is: $result"; // Outputs: The sum is: 15
  • 33. DEFAULT PARAMETER VALUES You can set default values for parameters. If a value is not provided during the function call, the default value will be used. function greet($name = "Guest") { echo "Hello, $name!"; } greet(); // Outputs: Hello, Guest! greet("Bob"); // Outputs: Hello, Bob!
  • 34. RETURNING VALUES Functions can return values using the return statement. Once a return statement is executed, the function stops executing. function square($number) { return $number * $number; } echo "The square of 4 is: " . square(4); // Outputs: The square of 4 is: 16
  • 35. CALL BY VALUE VS. CALL BY REFERENCE By default, PHP passes arguments to functions by value, meaning a copy of the variable is passed. If you want to pass a variable by reference (allowing the function to modify the original variable), you can use the & symbol. function increment(&$value) { $value++; } $num = 5; increment($num); echo $num; // Outputs: 6