Sunday, 20 September 2015

Some Array Functions:-

  1. array_diff() :- 
    •  The array_diff() function compares the values of two(or more) arrays, and returns the differences.
    • This function compares the values of two(or more) arrays, and return an array that contains the entire from array1 that are not present in array2 or array3 etc.
    • It can be explained further with a suitable example:-
                    array_diff().php:-
                   

                     Screenshot:-
                      

    2. array_intersect() :-
    • The array_intersect() function compares the values of two(or more) arrays, and returns the matches.
    • This function compares the values of two or more arrays, and return an array that contains the entries from array1 that are present in array2, array3 etc.
    • Now, explain it with a suitable example:-
                    array_intersect().php:-
                   

                    Screenshot:-
                     

     3.  array_push() ;-
    • The array_push() function inserts one or more elements to the end of an array.
    • Lets see an example:-
                    array_push().php :-
                    

                    Screenshot:-
                     

     4. array_pop() :-
    • The array_pop() function deletes the last element of an array.
    • Let consider an example:-
                    array_pop().php:-
                    

                     Screenshot:-
                      


     5. array_unique() ;-
    • The array_unique() function removes duplicate values from an array.
    • If two or more array values are the same, the first appearance will be kept and the other will be removed.
    • The returned array will keep the first array item's key type.
    • Consider an example:-
                     array_unique().php:-
                     

                     Screenshot:-
                     

     6. array_count():-
    • The array_count() function returns the number of elements in an array.
    • Consider an example:-
                    array_count().php:-
                     

                      Screenshot:-
                      

      7. array_merge() ;-
    • The array_merge() function merges one or more arrays into one array.
    • We can assign one array to the function, or as many as we like.
    • If two or more array elements have the same key, the last one overrides the others.
    • Let us consider an example:-
                    array_merge().php:-
                    

                     Screenshot:-
                     

Friday, 14 August 2015

PRINT v/s ECHO :-
  • In the previous posts, I have used both "print" and "echo" statements.
  • So, let me discuss about their differences.
  • Echo and Print are more or less the same.
  • Both are used to output data to the screen.
  • 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 while, print can take one argument.
  • Echo is comparatively faster than print.
The Echo Statement:-
  • The echo statement can be used with or without parentheses: "echo" or "echo()".
  • It can be explained further with a suitable example:-
          echo.php:-
          <html>
          <body>
          <?php
           echo "<h2>Learning PHP with Fun!</h2>";
           echo "This ", "string ", "was ", "made ", "with multiple parameters.";
            ?>
           </body>
           </html>

          Screenshot:-
          

  • We can display texts and variables with echo statement.
  • Consider an example:-
          echo1.php:-
          <?php
           $txt1 = "Learning PHP...!!!";
           $txt2 = "echo";
           $x = 3;
           $y = 4;

           echo "<h2>$txt1</h2>";
           echo "Implementing <b><i> $txt2 </i></b> statement<br/><br/>";
           echo "x = $x<br/>";
           echo "y = $y<br/>";
           echo "The result is:- x + y =";
           echo "<b>";
           echo $x + $y;
            echo "</b>";

          ?>
          Screenshot:-
          

The Print Statement :-
  • The print statement can be used with or without parentheses: "print" or "print()".
  • Consider an example:-
          print.php:-
          <?php

           print "<h2>Having Fun with PHP...</h2>";
           print "Using Print Statement";
         ?>

         Screenshot:-
         




  • We can display texts and variables with print statement. 

  •  Consider an example:-

  •               print1.php:-
                  <?php
                   $txt1 = "Learning PHP...!!!";
                   $txt2 = "print";
                   $x = 3;
                   $y = 4;

                   print "<h2>$txt1</h2>";
                   print "Implementing <b><i> $txt2 </i></b> statement<br/><br/>";
                   print "x = $x<br/>";
                   print "y = $y<br/>";
                   print "The result is:- x + y =";
                   print "<b>";
                   print $x + $y;
                   print "</b>";
                 ?>

                Screenshot:-
                


    PHP Strings :-
    • They are sequences of characters, like "String operations in PHP".
    • Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.
    • Let us consider an example:-
              strings.php:-
              <html>
              <body>
              <?php
               $x="Hi";

               print("<b><i>Singly Quoted Strings</i></b><br/>");
               $y='<b> $x </b>, How are U!';
               print($y); print("<br/><br/>");

               print("<b><i>Doubly Quoted Strings</i></b><br/>");
               $y="<b> $x </b>, How are U!";
               print($y);
               ?>
              </body>
              </html>

              Screenshot:-
              

                 
                Here, $x is printed as it is, when it is declared in single-quote(' '). 
                The value of the variable $x is evaluated when it is declared in double-quote(" ").

    • To concatenate two string variables together, we need to use the dot (.) operator.
    • Consider an example:-
              concatenate.php:-
              <html>

              <body>
              <?php
                $string1 = "Hello, ";
                $string2 = "Learning PHP...!!!";
                echo "First String :- <b> $string1 </b></br/>";
                echo "Second String :- <b> $string2 </b><br/><br/>";
                echo "<b><i> After Concatenation, by using dot(.) operator </i></b><br/>";
                echo $string1 . " " .$string2;
               ?>
              </body>
              </html>

              Screenshot:-
              
                
             
    • strlen() function can be used in PHP, to find the length of a string.
    • Consider an example:-
              strlen.php:-
              <html>

              <body>
              <?php
               echo "String used :-<b> <i> Hi Everyone </i> </b><br/><br/>";
               echo "The length of the String Is :- <br/>";
               echo "<b>";
               echo strlen("Hi Everyone");
               echo "</b>";
               ?>
               </body>
               </html>

              Screenshot:-
              
    • The strpos() function is used to search for a string or character within a string.
    • If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE.
    • Consider an example:-
              strpos.php:-
              <html>
              <body>
              <?php
               echo "String used :-<b> <i> Hi Everyone </i> </b><br/><br/>";
               echo "The Position of the String(Every) Is :- <br/>";
               echo "<b>";
               echo strpos("Hi Everyone","Every");
                echo "</b>";
                ?>
               </body>
               </html>

               Screenshot:-
               

                Here, the 'w' character of the 'world' string is at position 7, but it shows the position at 6
                It is so as the first position in the string is 0 and not 1.
    PHP Arrays:-
    • An array is a data structure that stores one or more similar type of values(homogeneous) in a single value.
    • If we want to store 10 numbers then instead of defining 10 variables, its easy to define an array of 10 length.
    • There are three different kind of arrays and each array value is accessed using an ID which is called array index.
      • Numeric Array :-
        • It can be stated as an array with a numeric index.
        • Values are stored and accessed in linear fashion.
        • These arrays can store numbers, strings and any object but their index will be presented by numbers. By default array index starts from zero.
        • It can be explained further with a suitable example.
                                  numeric array.php:-
                                  <html>
                                  <body>
                                  <?php

                                  echo "<b><i>First method to create array(array with integer)</i></b>";
                                  echo "<br/><br/>";
                                  $numbers = array( 1, 2, 3, 4, 5);
                                  echo "Array's Data is <b> $numbers[0] </b> <br/>";
                                  echo "Array's Data is <b> $numbers[1] </b> <br/>";
                                  echo "Array's Data is <b> $numbers[2] </b> <br/>";
                                  echo "Array's Data is <b> $numbers[3] </b> <br/>";
                                  echo "Array's Data is <b> $numbers[4] </b> <br/><br/>";
                                 foreach( $numbers as $value )
                                  {
                                    echo "Value is <b> $value </b> <br />";
                                  }
                                 echo "<br/>";

                                echo "<b><i>Second method to create array(array with string)</i></b>";
                                echo "<br/><br/>";
                                $numbers[0] = "one";
                                $numbers[1] = "two";
                                $numbers[2] = "three";
                                $numbers[3] = "four";
                                $numbers[4] = "five";
                                echo "The numbers first data :- <b> $numbers[0] </b><br/>";
                                echo "The numbers second data :- <b> $numbers[1] </b><br/>";
                                echo "The numbers third data :- <b> $numbers[2] </b><br/>";
                                echo "The numbers fourth data :- <b> $numbers[3] </b><br/>";
                                echo "The numbers fifth data :- <b> $numbers[4]</b><br/><br/>";
                                foreach( $numbers as $value )
                                  {
                                   echo "Value is <b> $value </b> <br />";
                                 }
                                ?>
                              </body>
                               </html>

                                Screenshot:-
                                

      • Associative Array :-
        • The associative arrays are very similar to numeric arrays in term of functionality but they are different in terms of their index.
        • It will have their index as string so that we can establish a strong association between key and values.
        • Consider an example, to store the salaries of employees in an array, we could use the employees names as the keys in the associative array, and the value would be their respective salary.
        • We should not keep associative array inside double quote while printing, otherwise it would not return any value.
        • Lets understand it further, with a suitable example
                                  associative array.php :-
                                  <html>
                                   <body>
                                   <?php

                                    echo "<b><i>Creating Associative Array by using array()</i></b>";
                                    echo "<br/><br/>";
                                    $salaries = array(
                                        "rahul" => 2000,
                                         "ram" => 1000,
                                           "raju" => 500
                                           );
                                    echo "Salary of Rahul is ". $salaries['rahul'] . "<br/>";
                                    echo "Salary of Ram is ". $salaries['ram']. "<br/>";
                                    echo "Salary of Raju is ". $salaries['raju']. "<br/><br/>";

                                    echo "<b><i>Creating Associative Array, without using array()</i></b>";                                             echo "<br/><br/>";
                                    $salaries['rahul'] = "high";
                                    $salaries['ram'] = "medium";
                                    $salaries['raju'] = "low";
                                    echo "Salary of Rahul is ". $salaries['rahul'] . "<br />";
                                    echo "Salary of Ram is ". $salaries['ram']. "<br />";
                                    echo "Salary of Raju is ". $salaries['raju']. "<br />";
                                    ?>
                                  </body>
                                  </html>

                                  Screenshot:-
                                  
      • Multidimensional Array :-
        • An array containing one or more arrays and values are accessed using multiple indices.
        • Let understand its concept, with an example
                                  multidimensional array.php:-
                                  <html>
                                  <body>
                                   <?php
                                   $marks = array(
                                   "rahul" => array
                                       (
                                      "english" => 67,
                                       "computer science" => 77
                                         ),
                                      "ram" => array
                                        (
                                        "english" => 61,
                                        "computer science" => 68
                                        ),
                                       "raju" => array
                                          (
                                        "english" => 78,
                                         "computer science" => 87
                                         )
                                       );

                                      echo "<b><i>Accessing the values of multi-dimensional array</i></b>";                                               echo "<br/><br/>";

                                      echo "Marks for Rahul in English : " ;
                                      echo $marks['rahul']['english'] . "<br />";
                                      echo "Marks for Rahul in Computer Science  : " ;
                                      echo $marks['rahul']['computer science'] . "<br /> <br />";

                                      echo "Marks for Ram in English : " ;
                                      echo $marks['ram']['english'] . "<br />";
                                      echo "Marks for Ram in Computer Science  : " ;
                                      echo $marks['ram']['computer science'] . "<br /> <br />";

                                      echo "Marks for Raju in English : " ;
                                      echo $marks['raju']['english'] . "<br />";
                                      echo "Marks for Raju in Computer Science  : " ;
                                      echo $marks['raju']['computer science'] . "<br /><br />";

                                      ?>
                                    </body>
                                    </html>

                                     Screenshot:-
                                     

    Wednesday, 12 August 2015

    PHP Break and Continue Statements :-
    • The Break Statement :-
        1. The PHP break keyword is used to terminate the execution of a loop prematurely.
        2. By using break statement/keyword, whenever we want to exit from the loop we can come out.
        3. After coming out of a loop, the immediate statements to the loop will be executed.
        4. It can be example further with a suitable example:-
                                  break.php:-
                                  <html>
                                  <body>
                                  <?php
                                    $i = 0;

                                   echo "The value of <b>i:-</b><br/><br/>";
                                  while( $i < 5)
                                    {
                                   $i++;
                                   echo "<b>$i</b><br/>";
                                  if( $i == 3 )
                                  break;
                                  }
                                 echo "<br/>";
                                 echo "<b> Break is used </b><br/><br/>";
                                 echo ("Loop stopped at i = <b> $i </b>" );
                                 ?>
                               </body>
                               </html>

                                Screenshot:-
                                
    • The Continue Statement :-
        1. The continue keyword is used to halt the current iteration of a loop but it does not terminate the loop.
        2. If we used the continue keyword, rest of the loop code is skipped and next pass starts.
        3. With a suitable example, it can be understand properly:-
                                  continue.php:-
                                  <html>
                                  <body>
                                  <?php
                                   $array = array( 1, 2, 3, 4, 5);

                                   echo "Array's Data is <b> $array[0] </b> <br/>";
                                   echo "Array's Data is <b> $array[1] </b> <br/>";
                                   echo "Array's Data is <b> $array[2] </b> <br/>";
                                   echo "Array's Data is <b> $array[3] </b> <br/>";
                                   echo "Array's Data is <b> $array[4] </b> <br/><br/>";

                                  echo "<b><i>Continue is used, when i's value is equal to 3</i></b>";
                                  echo "<br/><br/>";
                                  echo "So, now the value is:-<br/>";

                                  foreach( $array as $value )
                                  {
                                    if( $value == 3 )
                                    continue;
                                    echo "<b>$value</b> <br />";
                                  }
                                  ?>
                                </body>
                                </html>

                                 Screenshot:-
                                 
                                  

    Tuesday, 11 August 2015

    PHP Loop Types:-

    • Loops in PHP are used to execute the same block of code a specified number of times.
    • PHP supports following four loop types :-
      • for loop :- The for statement is used when you know how many times you want to execute a statement or a block of statements. 
                        
                         Syntax:-
                        for (initialization; condition; increment)
                          {
                              code to be executed;
                          }
          
                       
                         Example :-
                         for loop.php :-
                         <html>
                         <body>
                          <?php
                         $a = 0; //Initializing the variable, i.e, a
                         $b = 0; //the variable "b" has been assigned with a value "0"

                         for( $i=0; $i<5; $i++ )
                           {
                           echo "i's value:- $i<br/>";
                           $a += 5;
                           echo "a's value:- $a<br/>";
                            $b += 3;
                            echo "b's value:- $b<br/><br/>";
                           }
                         echo ("At the end of the loop, <b> i=$i, </b> <b> a=$a </b> and <b> b=$b </b>" );
                         ?>
                        </body>
                        </html>
                         

                        Screenshot :-
                        
      • while loop :- The while statement will execute a block of code, if the test expression is true. After the code has executed the test expression will again be evaluated and the loop will continue until the test expression is found to be false.
                       Syntax:-
                       while (condition)
                         {
                             code to be executed;
                         }

                        
                        Example:-
                        <html>
                        <body>
                        <?php
                         $i = 0;
                         $num = 30;

                        echo "Initial Value of <b> i = $i and num = $num </b><br/><br/>";
                        echo "<b><i> While Loop Starts </i></b><br/><br/>";

                         while( $i < 5)
                          {
                             echo "num's value:- $num<br/>";
                             $num--;
                             $i++;
                             echo "i's value:- $i<br/><br/>";
                          }

                        echo ("Loop stopped at <b> i = $i </b>  and <b> num = $num </b>" );
                        ?>
                       </body>
                       </html>

                       Screenshot:-
                       
      • do...while loop:-  The do...while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.
                       Syntax:-
                       do
                           {
                             code to be executed;
                           }while (condition);

                       Example :-
                       <html>
                       <body>
                      <?php
                       $i = 0;

                       echo "Initial Value of <b> i = $i </b><br/><br/>";
                       echo "<b><i> Do...While Loop Starts </i></b><br/><br/>";

                       do
                        {
                        $i++;
                        echo "i's value:- $i<br/><br/>";
                        }while( $i < 10 );

                       echo ("Loop stopped at <b> i = $i </b>" );
                        ?>
                      </body>
                      </html>

                      Screenshot:-
                      
      • foreach loop :-  The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.

                       Syntax:-
                       foreach (array as value)
                         {
                            code to be executed;
                        }       

                        
                        Example:-
                       <html>
                       <body>
                       <?php
                        $array = array( 1, 2, 3, 4, 5);

                        echo "Array's Data is <b> $array[0] </b> <br/>";
                        echo "Array's Data is <b> $array[1] </b> <br/>";
                        echo "Array's Data is <b> $array[2] </b> <br/>";
                        echo "Array's Data is <b> $array[3] </b> <br/>";
                        echo "Array's Data is <b> $array[4] </b> <br/><br/>";


                        echo "<b><i> For Each Loop Starts </i></b><br/><br/>";
                        foreach( $array as $value )
                         {
                        echo "Value is <b> $value </b> <br/> ";
                         }
                        ?>

                     </body>
                      </html>           

                        
                        Screenshot:-
                         


                        
    PHP Decision Making Concepts :-

  • The if, elseif ...else and switch statements are used to take decision based on the different condition.
  • PHP supports following three decision making statements:
    • if...else statement :-  This statement is used if we want to execute a set of code when a condition is true and another if the condition is not true. 
              Syntax:-
       
              if (condition)
                  code to be executed if condition is true;
              else
                  code to be executed if condition is false;

            Example :-

            if..else.php :-
            <html>
             <body>
             <?php
              $y=1;
             if($y==1)
             echo "<b> Y's value is displayed </b>";
             else
             echo "<b> Y's value is not displayed </b>";
            ?>
           </body>
           </html>

             Screenshot :-
             
              
    • elseif statement :- It is used with the if...else statement to execute a set of code if one of several conditions are true.
              Syntax:-
       
               if (condition)
                   code to be executed if condition is true;
               elseif (condition)
                    code to be executed if condition is true;
                else
                    code to be executed if condition is false;

                Example:-

                elseif.php
                <html>
                 <body>
                 <?php
                   $x=date("D");
                    echo "<b>Today is :- $x </b> <br/>";

                  if ($x=="Fri")
                  echo "So, have a nice weekend!";
                   elseif ($x=="Sun")
                   echo "So, have a nice Sunday!";
                   else
                   echo "So, have a nice day!";
                    ?>
                  </body>
                  </html>

                  Screenshot :-
                   

    • switch statement :-  It is used if we want to select one of many blocks of code to be executed, use the switch statement.  The switch statement is used to avoid long blocks of if..elseif..else code.
              Syntax:-
             
              switch (expression)
                {
                   case label1:
                           code to be executed if expression = label1;
                          break;
                   case label2:
                         code to be executed if expression = label2;
                         break;
                  default:
                        code to be executed
                  if expression is different from both label1 and label2;
               }

              Example:-

              switch.php:-
               <html>
                <body>
               <?php
               $d=date("D");
               echo "<b>Today is :- $d </b> <br/>";

                   switch ($d)
                   {
                  case "Mon":
                  echo "So, today is Monday";
                  break;

                  case "Tue":
                  echo "So, today is Tuesday";
                   break;

                  case "Wed":
                  echo "So, today is Wednesday";
                  break;

                  case "Thu":
                  echo "So, today is Thursday";
                   break;

                   case "Fri":
                   echo "So, today is Friday";
                   break;

                   case "Sat":
                   echo "So, today is Saturday";
                   break;

                   case "Sun":
                   echo "So, today is Sunday";
                   break;

                   default:
                  echo "oh,ho!!! None of the above";
                 }
                 ?>
                </body>
                 </html>

                  Screenshots :-
                  

    Monday, 10 August 2015

    PHP Operators :- 
    • Operators are used to operate on values.
    • Consider an example, "1+3=4". Here, "1 & 3" are called as operands and "+" is called as operators.
    • Types of Operators :-
        1. Arithmetic Operators.
        2. Comparison Operators.
        3. Logical(or Relational) Operators.
        4. Assignment Operators.
        5. Conditional(or ternary) Operators.
    • It can be illustrated further with suitable examples :-
     arithematic operators.php :-
    <html>
    <head><title>Arithmetical Operators</title><head>
    <body>
    <?php
        $x = 62;
        $y = 40;
        
        $z = $x + $y;
        echo "Addtion Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x - $y;
        echo "Substraction Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x * $y;
        echo "Multiplication Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x / $y;
        echo "Division Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x % $y;
        echo "Modulus Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x++; 
        echo "Increment Operation Result: <b> $z </b> <br/> <br/>";
        
        $z = $x--; 
        echo "Decrement Operation Result: <b> $z </b> <br/> <br/>";
    ?>
    </body>
    </html>

    Screenshot:-

    comparison operators.php :-
    <html>
    <head><title>Comparision Operators</title><head>
    <body>
    <?php
        $x = 62;
        $y = 40;
        

        echo "<b> x =$x </b>"; echo "<br/>";
        echo "<b> y =$y </b>"; echo "<br/> <br/>";


        if( $x == $y ){
           echo "x is equal to y<br/><br/>";
        }else{
           echo "x is not equal to y<br/><br/>";
        }

        if( $x > $y ){
           echo "x is greater than  y<br/><br/>";
        }else{
           echo "x is not greater than y<br/><br/>";
        }
        if( $x < $y ){
           echo "x is less than  y<br/><br/>";
        }else{
           echo "x is not less than y<br/><br/>";
        }
        if( $x != $y ){
           echo "x is not equal to y<br/><br/>";
        }else{
           echo "x is equal to y<br/><br/>";
        }
        if( $x >= $y ){
           echo "x is either grater than or equal to y<br/><br/>";
        }else{
           echo "x is neither greater than nor equal to y<br/><br/>";
        }
        if( $x <= $y ){
           echo "x is either less than or equal to y<br/><br/>";
        }else{
           echo "x is neither less than nor equal to y<br/><br/>";
        }
    ?>
    </body>
    </html>

    Screenshot:-


    logical operators.php:-
    <html>
    <head><title>Logical Operators</title><head>
    <body>
    <?php
        $a = 42;
        $b = 21;

        echo "<b> a =$a </b>"; echo "<br/>";
        echo "<b> b =$b </b>"; echo "<br/> <br/>";

        if( $a && $b ){
           echo "Both a and b are true<br/>";
        }else{
           echo "Either a or b is false<br/>";
        }
        if( $a and $b ){
           echo "Both a and b are true<br/>";
        }else{
           echo "Either a or b is false<br/>";
        }
        if( $a || $b ){
           echo "Either a or b is true<br/>";
        }else{
           echo "Both a and b are false<br/>";
        }
        if( $a or $b ){
           echo "Either a or b is true<br/>";
        }else{
           echo "Both a and b are false<br/>";
        }
    ?>
    </body>
    </html>

    Screenshot:-


    assignment operators.php :-
    <html>
    <head><title>Assignment Operators</title><head>
    <body>
    <?php
        $a = 42;
        $b = 20;
        
        echo "<b> a =$a </b>"; echo "<br/>";
        echo "<b> b =$b </b>"; echo "<br/> <br/>";

        $c = $a + $b;
        echo "c = a + b<br/>";   
        echo "Addtion Operation Result: $c(c's value) <br/><br/>";

        $c += $a; 
        echo "c = c + a<br/>"; 
        echo "Add AND Assigment Operation Result: $c(c value was 42 + 20 = 62) <br/><br/>";

        $c -= $a; 
        echo "c = c - a<br/>";
        echo "Subtract AND Assignment Operation Result: $c(c value was 42 + 20 + 42 = 104) <br/><br/>";

        $c *= $a; 
        echo "c = c * a<br/>";
        echo "Multiply AND Assignment Operation Result: $c(c value was 104 - 42 = 62) <br/><br/>";

        $c /= $a; 
        echo "c = c / a<br/>"; 
        echo "Division AND Assignment Operation Result: $c(c value was 62 * 42 = 2604) <br/><br>";

        $c %= $a; 
        echo "c = c % a<br/>";
        echo "Modulus AND Assignment Operation Result: $c(c value was 2604/42 = 62) <br/><br/>";
    ?>
    </body>
    </html>

    Screenshot:-


    conditional operators.php :-
    <html>
    <head><title>Conditional Operators</title><head>
    <body>
    <?php
        $a = 10;
        $b = 20;
        
        echo "<b> a =$a </b>"; echo "<br/>";
        echo "<b> b =$b </b>"; echo "<br/> <br/>";

        echo "result = (a > b) ? a : b<br/>";
        $result = ($a > $b ) ? $a :$b;
        echo "Value of result is <b> $result </b> <br/><br/>";

        echo "result = (a < b) ? a : b<br/>";
        $result = ($a < $b ) ? $a :$b;
        echo "Value of result is <b> $result </b> <br/><br/>";
    ?>
    </body>
    </html>

    Screenshot:-