Posts

Showing posts from 2021

PHP Output Statements

 In PHP, we can get output by two ways, 1) echo 2) print PHP echo and print Statements echo  and  print  are more or less the same. They are both used to output data to the screen. The differences are small:  echo  has no return value while  print  has a return value of 1 so it can be used in expressions.  echo  can take multiple parameters (although such usage is rare) while  print  can take one argument.  echo  is marginally faster than  print . SHOW TEXT <?php echo   "<h2>PHP is Fun!</h2>" ; echo   "Hello RK!<br>" ; echo   "I'm about to learn PHP!<br>" ; echo   "This " ,  "string " ,  "was " ,  "made " ,  "with multiple parameters." ; ?> SHOW VARIABLE <?php $txt1 =  "Learn PHP" ; $txt2 =  "With RK" ; $x =  5 ; $y =  4 ; echo   "<h2>"  . $txt1 .  "</h2>" ; echo   "Study PHP "  . $txt2 .  "<br>&quo

PHP Variables

  In PHP, a variable starts with the  $  sign, followed by the name of the variable: for example: <?php $txt =  "Hello RK!" ; $x =  5 ; $y =  10.5 ; ?> A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). 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: Remember that PHP variable names are case-sensitive! Output The PHP  echo  statement is often used to output data to the screen. The following example will show how to output text and a variable: Example 1: <?php $txt =  "RK" ; echo   "I love $txt!" ; ?> Example 2: <?php $txt =  "RK" ; echo   &q

PHP Comments

  Comments in PHP A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: Let others understand your code Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code PHP supports several ways of commenting: Single Line Commenting < !DOCTYPE  html > < html > < body > <?php // This is a single-line comment # This is also a single-line comment ?> < /body > < /html > Multi line Commenting < !DOCTYPE  html > < html > < body > <?php /* This is a multiple-lines comment block that spans over multiple lines */ ?> < /body > < /html >