Skip to main content

Data Types and More in PHP

Tutorial Title: Data Types and More in PHP
Course: PHP
Instructor: Muhammad Samim


1. Variables in PHP

  • Variable means container which keeps the data. Different types of Variables store different types of data
  • Variables in PHP are case sensitive
  • Variable starts with $ symbol in PHP
  • Variable cant be started with numbers
  • Variable can't have -
  • $variableName = "Muhammad Samim"; //String data
  • $variableName = 200; //Numbers
  • $variableName = 200.5; //Float
  • echo $variableName; //Displays whats inside variable
  • echo $variableName . $variableName; //Dot will concatenate two variables
  • echo $variableName . " " .   $variablename; //Will give space between data of two variable while displaying.
  • PHP string variable can store HTML tags inside e.g $variableName = "<h1>Muhammad Samim </h1>";

2. Math in PHP
  • Precedence applies in doing maths in PHP
  • echo 200 / 200; //Displays the result of Division
  • echo 200 * 200; //Displays the result of Multiplication
  • echo 200 + 200; //Displays the result of Addition
  • echo 200 - 200; //Displays the result of Subtraction
  • echo 200 + 200 / 200; //Displays the result, first it will be divided then will be added due to rule of precedence
  • echo (200 + 200) / 200; //Displays  the result, here first will be added then will be divided due to rule of precedence as Parenthesis priority is in first than Division 
  • $variableName1 = 200;
  • $variableName2 = 300;
  • echo $variableName1 + $variableName2; //Displays the result of two variables

3. Array
  • Array stores same or different types of data in one variable by assigning index number to each value in PHP
  • $arrayName = array(200,400.3,"Muhammad Samim",500);
  • or $arrayname = [200,400.3,"Muhammad Samim",500]; // Both are same
  • echo $arrayName[indexNumber]; //Displays the value of given index number
  • print_r($arrayName); //Displays the complete structure of array with index numbers and their values.

4. Associative Array
  • Its same like regular array we knew above but here we can give code or name instead of index number
  • $arrayName = array("firstName" => "Muhammad", "lastName" => "Samim", "Number" => "07"); //Associating value with names of code instead of index number
  • echo $arrayName["firstName"] . " " . $arrrayName["lastName"] . " " . $arrayName["number"]; //Displays the data of array by associated names
  • print_r($arrayName); //Displays the complete structure of array


Comments

Popular posts from this blog

External Page Submission/Submission to another page

Tutorial Title:   External Page Submission/Submission to another page Course: PHP Instructor: Muhammad Samim 1. Submitting action from one page to another page 2. First make one page with name page1.php <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Document</title> </head> <body>      <form action="page2.php" method="post"> //It will direct from page1.php to page2.php           <br><input type="text" placeholder="Email" name="anyNameForEmail">     <br><input type="password" placeholder="Password" name="anyNameForPassword">     <br><input type="submit" name="click">    </form>   </body> </html> 3. Second make another file with name page2.php <?php if(isset($_POST["click"])){     $anyNameO...

Extracting Information from form

Tutorial Title:  Extracting Information from form Course: PHP Instructor: Muhammad Samim 1. <?php if(isset($_POST["anyName"])) { $anyNameOfVariableForEmail = $_POST["anyNameForEmail"]; //Now because of it email must be typed otherwise it will not work $anyNameOfVariableForPassword = $_POST["anyNameForPassord"];//Now because of it password must be typed otherwise it will not work echo $anyNameOfVariableForEmail; //It will display the email echo $anyNameOfVariableForPassword; //It will display the password } ?> <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>Document</title> </head> <body>      <form action="21form.php" method="post">        <input type="text" placeholder="Email" name="anyNameForEmail">        <input type="password" placeholder="...