Saturday, 3 December 2022

Basic Fundamentals of PHP Language

 PHP Response.

To get response from PHP Language we use echo command following the response.

<?php

echo response;

?>

Response could be:

  • String
  • Integer
  • Float
  • Boolean
  • HTML Tags

String:

Any thing that is enclosed inside double quotes (inverted commas) or single quotes (Apostrophes) is know as String in PHP.

Integer:

Any whole Number (a number without decimal point) is known as Integer in PHP, don't enclose Integers in single or double quotes.

Float:

Any Real Number (a number with decimal point) is known as Float in PHP, don't enclose Float in single or double quotes.

Boolean:

Two words true and false or commonly known as Boolean data, don't enclose Boolean in single quotes or double quotes.

HTML Tags:

HTML tags can also be used as PHP response, always enclose HTML tags in single or double quotes.

Example:

<?php

echo "This is a String";

echo 1234;  // Integer Response

echo 23.34; // Float Response

echo true; // Boolean Response

echo "<p> This is a Paragraph </p>"; // HTML Response

?>

Variables:

As we know from mathematics variables or names used to assign values to them, and afterwards where ever we need this value, we response the variable name and PHP returns the value stored in that variable.

Note: One variable can have one value at a time, but can have different values in different statements

Example:

<?php

$studentname="Muhammad Asif";

$rollno=1234;

$height=5.6;

$married=true;

//to see the values response variable names

echo $studentname;

echo $rollno;

echo $height;

echo $married;

?>

Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)

Note: PHP Variable names are case sensitive.




No comments:

Post a Comment