SlideShare a Scribd company logo
DATA TYPES AND
VARIABLES IN PHP
PHP DETERMINES THE DATA TYPE DEPENDING ON THE
ATTRIBUTES OF THE SUPPLIED DATA.
<?php
$my_var = 1;
echo $my_var;
?>
<?php
$my_var = 3.14;
echo $my_var;
?>
<?php
$my_var ="Hypertext Pre Processor";
echo $my_var;
?>
PHP ALSO ALLOWS YOU TO CAST THE DATA TYPE.
THIS IS KNOWN AS EXPLICIT CASTING.
<?php
$a = 1;
$b = 1.5;
$c = $a + $b;
$c = $a + (int) $b;
echo $c;
?>
Operator Name Description Example Output
+ Addition
Summation of x
and y
1 + 1; 2
– Subtraction
Difference
between x and y
1 – 1; 0
* Multiplication Multiplies x and y 3 * 7; 21
/ Division
Quotient of x and
y
45 / 5; 9
% PHP Modulus
Gives remainder of
dividing x and y
10 % 3; 1
-n Negation
Turns n into a
negative number
-(-5); 5
x . y Concatenation
Puts together x and
y
“PHP” . ”
ROCKS”;10 . 3;
PHP ROCKS103
Operator Name Description Example Output
x = ? assignment
Assigns the value
of x to ?
$x = 5; 5
x += ? addition
Increments the
value of x by ?
$x = 2;$x += 1; 3
X -= ? subtraction
Subtracts ? from
the value of x
$x = 3;$x -= 2; 1
X *=? multiplication
Multiplies the
value of x ? times
$x = 0;$x *=9; 0
X /=? division Quotient of x and ? $x = 6;$x /=3; 2
X %=? modulus
The reminder of
dividing x by?
$x = 3;$x %= 2; 1
X .=? concatenate Puts together items
” $x = ‘Pretty’;
$x .= ‘ Cool!’;”
Pretty Cool!
perator Name Description Example Output
X == y Equal
Compares x and y then
returns true if they are
equal
1 == “1”; True or 1
X === y identical
Compares both values
and data types.
1 === “1”;
False or 0. Since 1 is
integer and “1” is string
X != y, x <> y PHP Not equal
Compares values of x
and y. returns true if the
values are not equal
2 != 1; True or 1
X > y Greater than
Compares values of x
and y. returns true if x is
greater than y
3 > 1; True or 1
X < y Less than
Compares values of x
and y. returns true if x is
less than y
2 < 1; False or 0
X >= y Greater than or equal
Compares values of x
and y. returns true if x is
greater than or equal to
y
1 >=1 True or 1
X <= y Less than or equal
Compares values of x
and y. returns true if x is
greater than or equal to
y
8 <= 6 False or 0
Operator Name Description Example Output
X and y, x && y And
Returns true if both x
and y are equal
1 and 4;True&& False; True or 1False or 0
X or y, x || y Or
Returns true if either
x or y is true
6 or 9;0 || 0; True or 1False or 0
X xor y Exclusive or, xor
Returns true if only x
is true or only y is
true
1 xor 1;1 xor 0; False or 0True or 1
!x Not
Returns true if x is
false and false if x is
true
!0; True or 1
<?php
$globalVar = "I am global";
function testScope() {
global $globalVar;
echo $globalVar . "n";
}
testScope();
?>
<?php
// Student information
$studentName = "Alice"; // String
$marks = [85, 78, 92, 88, 76]; // Array of integers
$passingMarks = 50; // Integer
$totalSubjects = count($marks); // Integer
// Calculate total and average marks
$totalMarks = array_sum($marks); // Integer
$averageMarks = $totalMarks / $totalSubjects; // Float
// Check if the student passed all subjects
$hasPassedAllSubjects = true; // Boolean
foreach ($marks as $mark) {
if ($mark < $passingMarks) {
$hasPassedAllSubjects = false;
break;
}
}
// Display results
echo "Student Name: $studentNamen";
echo "Total Marks: $totalMarksn";
echo "Average Marks: " . number_format($averageMarks, 2) . "n";
// Determine and display pass/fail status
if ($hasPassedAllSubjects) {
echo "Status: Passedn";
} else {
echo "Status: Failedn";
}
// Display detailed results
echo "nSubject-wise Marks:n";
foreach ($marks as $index => $mark) {
echo "Subject " . ($index + 1) . ": $markn";
}
?>

More Related Content

Similar to Data types and variables in php for writing (20)

Introduction to php
Introduction to phpIntroduction to php
Introduction to php
sagaroceanic11
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
Norhisyam Dasuki
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
Open Gurukul
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Saraswathi Murugan
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
Jesus Obenita Jr.
 
Php
PhpPhp
Php
Vishnu Raj
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
Mohammad Imam Hossain
 
PHP-Overview.ppt
PHP-Overview.pptPHP-Overview.ppt
PHP-Overview.ppt
Akshay Bhujbal
 
PHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenowPHP-01-Overview.pptfreeforeveryonecomenow
PHP-01-Overview.pptfreeforeveryonecomenow
oliverrobertjames
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
Todd Barber
 
Php Basics Iterations, looping
Php Basics Iterations, loopingPhp Basics Iterations, looping
Php Basics Iterations, looping
Muthuganesh S
 
Php Chapter 1 Training
Php Chapter 1 TrainingPhp Chapter 1 Training
Php Chapter 1 Training
Chris Chubb
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
adityathote3
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
mysthicrious
 
Php + my sql
Php + my sqlPhp + my sql
Php + my sql
Ashen Disanayaka
 
PHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.pptPHP teaching ppt for the freshers in colleeg.ppt
PHP teaching ppt for the freshers in colleeg.ppt
vvsofttechsolution
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
NBACriteria2SICET
 
Php Basic
Php BasicPhp Basic
Php Basic
Md. Sirajus Salayhin
 

More from vishal choudhary (20)

Pixel to Percentage conversion Convert left and right padding of a div to per...
Pixel to Percentage conversion Convert left and right padding of a div to per...Pixel to Percentage conversion Convert left and right padding of a div to per...
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
esponsive web design means that your website (
esponsive web design means that your website (esponsive web design means that your website (
esponsive web design means that your website (
vishal choudhary
 
function in php using like three type of function
function in php using  like three type of functionfunction in php using  like three type of function
function in php using like three type of function
vishal choudhary
 
data base connectivity in php using msql database
data base connectivity in php using msql databasedata base connectivity in php using msql database
data base connectivity in php using msql database
vishal choudhary
 
software evelopment life cycle model and example of water fall model
software evelopment life cycle model and example of water fall modelsoftware evelopment life cycle model and example of water fall model
software evelopment life cycle model and example of water fall model
vishal choudhary
 
software Engineering lecture on development life cycle
software Engineering lecture on development life cyclesoftware Engineering lecture on development life cycle
software Engineering lecture on development life cycle
vishal choudhary
 
strings in php how to use different data types in string
strings in php how to use different data types in stringstrings in php how to use different data types in string
strings in php how to use different data types in string
vishal choudhary
 
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
OPEN SOURCE WEB APPLICATION DEVELOPMENT  questionOPEN SOURCE WEB APPLICATION DEVELOPMENT  question
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
vishal choudhary
 
web performnace optimization using css minification
web performnace optimization using css minificationweb performnace optimization using css minification
web performnace optimization using css minification
vishal choudhary
 
web performance optimization using style
web performance optimization using styleweb performance optimization using style
web performance optimization using style
vishal choudhary
 
Data types and variables in php for writing and databse
Data types and variables in php for writing  and databseData types and variables in php for writing  and databse
Data types and variables in php for writing and databse
vishal choudhary
 
Data types and variables in php for writing
Data types and variables in php for writingData types and variables in php for writing
Data types and variables in php for writing
vishal choudhary
 
sofwtare standard for test plan it execution
sofwtare standard for test plan it executionsofwtare standard for test plan it execution
sofwtare standard for test plan it execution
vishal choudhary
 
Software test policy and test plan in development
Software test policy and test plan in developmentSoftware test policy and test plan in development
Software test policy and test plan in development
vishal choudhary
 
function in php like control loop and its uses
function in php like control loop and its usesfunction in php like control loop and its uses
function in php like control loop and its uses
vishal choudhary
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
PHP introduction how to create and start php
PHP introduction how to create and start phpPHP introduction how to create and start php
PHP introduction how to create and start php
vishal choudhary
 
SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
vishal choudhary
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
vishal choudhary
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
vishal choudhary
 
Pixel to Percentage conversion Convert left and right padding of a div to per...
Pixel to Percentage conversion Convert left and right padding of a div to per...Pixel to Percentage conversion Convert left and right padding of a div to per...
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
esponsive web design means that your website (
esponsive web design means that your website (esponsive web design means that your website (
esponsive web design means that your website (
vishal choudhary
 
function in php using like three type of function
function in php using  like three type of functionfunction in php using  like three type of function
function in php using like three type of function
vishal choudhary
 
data base connectivity in php using msql database
data base connectivity in php using msql databasedata base connectivity in php using msql database
data base connectivity in php using msql database
vishal choudhary
 
software evelopment life cycle model and example of water fall model
software evelopment life cycle model and example of water fall modelsoftware evelopment life cycle model and example of water fall model
software evelopment life cycle model and example of water fall model
vishal choudhary
 
software Engineering lecture on development life cycle
software Engineering lecture on development life cyclesoftware Engineering lecture on development life cycle
software Engineering lecture on development life cycle
vishal choudhary
 
strings in php how to use different data types in string
strings in php how to use different data types in stringstrings in php how to use different data types in string
strings in php how to use different data types in string
vishal choudhary
 
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
OPEN SOURCE WEB APPLICATION DEVELOPMENT  questionOPEN SOURCE WEB APPLICATION DEVELOPMENT  question
OPEN SOURCE WEB APPLICATION DEVELOPMENT question
vishal choudhary
 
web performnace optimization using css minification
web performnace optimization using css minificationweb performnace optimization using css minification
web performnace optimization using css minification
vishal choudhary
 
web performance optimization using style
web performance optimization using styleweb performance optimization using style
web performance optimization using style
vishal choudhary
 
Data types and variables in php for writing and databse
Data types and variables in php for writing  and databseData types and variables in php for writing  and databse
Data types and variables in php for writing and databse
vishal choudhary
 
Data types and variables in php for writing
Data types and variables in php for writingData types and variables in php for writing
Data types and variables in php for writing
vishal choudhary
 
sofwtare standard for test plan it execution
sofwtare standard for test plan it executionsofwtare standard for test plan it execution
sofwtare standard for test plan it execution
vishal choudhary
 
Software test policy and test plan in development
Software test policy and test plan in developmentSoftware test policy and test plan in development
Software test policy and test plan in development
vishal choudhary
 
function in php like control loop and its uses
function in php like control loop and its usesfunction in php like control loop and its uses
function in php like control loop and its uses
vishal choudhary
 
introduction to php and its uses in daily
introduction to php and its uses in dailyintroduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
PHP introduction how to create and start php
PHP introduction how to create and start phpPHP introduction how to create and start php
PHP introduction how to create and start php
vishal choudhary
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
vishal choudhary
 
Ad

Recently uploaded (20)

Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
HVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdfHVAC Air Filter Equipment-Catalouge-Final.pdf
HVAC Air Filter Equipment-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdfISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
ISO 5011 Air Filter Catalogues .pdf
ISO 5011 Air Filter Catalogues      .pdfISO 5011 Air Filter Catalogues      .pdf
ISO 5011 Air Filter Catalogues .pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Software Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha TasnuvaSoftware Engineering Project Presentation Tanisha Tasnuva
Software Engineering Project Presentation Tanisha Tasnuva
tanishatasnuva76
 
Ad

Data types and variables in php for writing

  • 2. PHP DETERMINES THE DATA TYPE DEPENDING ON THE ATTRIBUTES OF THE SUPPLIED DATA. <?php $my_var = 1; echo $my_var; ?> <?php $my_var = 3.14; echo $my_var; ?> <?php $my_var ="Hypertext Pre Processor"; echo $my_var; ?>
  • 3. PHP ALSO ALLOWS YOU TO CAST THE DATA TYPE. THIS IS KNOWN AS EXPLICIT CASTING. <?php $a = 1; $b = 1.5; $c = $a + $b; $c = $a + (int) $b; echo $c; ?>
  • 4. Operator Name Description Example Output + Addition Summation of x and y 1 + 1; 2 – Subtraction Difference between x and y 1 – 1; 0 * Multiplication Multiplies x and y 3 * 7; 21 / Division Quotient of x and y 45 / 5; 9 % PHP Modulus Gives remainder of dividing x and y 10 % 3; 1 -n Negation Turns n into a negative number -(-5); 5 x . y Concatenation Puts together x and y “PHP” . ” ROCKS”;10 . 3; PHP ROCKS103
  • 5. Operator Name Description Example Output x = ? assignment Assigns the value of x to ? $x = 5; 5 x += ? addition Increments the value of x by ? $x = 2;$x += 1; 3 X -= ? subtraction Subtracts ? from the value of x $x = 3;$x -= 2; 1 X *=? multiplication Multiplies the value of x ? times $x = 0;$x *=9; 0 X /=? division Quotient of x and ? $x = 6;$x /=3; 2 X %=? modulus The reminder of dividing x by? $x = 3;$x %= 2; 1 X .=? concatenate Puts together items ” $x = ‘Pretty’; $x .= ‘ Cool!’;” Pretty Cool!
  • 6. perator Name Description Example Output X == y Equal Compares x and y then returns true if they are equal 1 == “1”; True or 1 X === y identical Compares both values and data types. 1 === “1”; False or 0. Since 1 is integer and “1” is string X != y, x <> y PHP Not equal Compares values of x and y. returns true if the values are not equal 2 != 1; True or 1 X > y Greater than Compares values of x and y. returns true if x is greater than y 3 > 1; True or 1 X < y Less than Compares values of x and y. returns true if x is less than y 2 < 1; False or 0 X >= y Greater than or equal Compares values of x and y. returns true if x is greater than or equal to y 1 >=1 True or 1 X <= y Less than or equal Compares values of x and y. returns true if x is greater than or equal to y 8 <= 6 False or 0
  • 7. Operator Name Description Example Output X and y, x && y And Returns true if both x and y are equal 1 and 4;True&& False; True or 1False or 0 X or y, x || y Or Returns true if either x or y is true 6 or 9;0 || 0; True or 1False or 0 X xor y Exclusive or, xor Returns true if only x is true or only y is true 1 xor 1;1 xor 0; False or 0True or 1 !x Not Returns true if x is false and false if x is true !0; True or 1
  • 8. <?php $globalVar = "I am global"; function testScope() { global $globalVar; echo $globalVar . "n"; } testScope(); ?>
  • 9. <?php // Student information $studentName = "Alice"; // String $marks = [85, 78, 92, 88, 76]; // Array of integers $passingMarks = 50; // Integer $totalSubjects = count($marks); // Integer // Calculate total and average marks $totalMarks = array_sum($marks); // Integer $averageMarks = $totalMarks / $totalSubjects; // Float // Check if the student passed all subjects $hasPassedAllSubjects = true; // Boolean foreach ($marks as $mark) { if ($mark < $passingMarks) { $hasPassedAllSubjects = false; break; } } // Display results echo "Student Name: $studentNamen"; echo "Total Marks: $totalMarksn"; echo "Average Marks: " . number_format($averageMarks, 2) . "n"; // Determine and display pass/fail status if ($hasPassedAllSubjects) { echo "Status: Passedn"; } else { echo "Status: Failedn"; } // Display detailed results echo "nSubject-wise Marks:n"; foreach ($marks as $index => $mark) { echo "Subject " . ($index + 1) . ": $markn"; } ?>