humanware

php_training_day3_string_operators

Aug 7th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. /*
  3. .   concatenate     Combine $x & $y
  4. .=  concatenate assignment  append $x & y
  5.  
  6. $x = 'Test';
  7. $y = 'Test 2';
  8. echo $x .= ' Test 3';
  9.  
  10. // echo $x . ' ' . $y;
  11. $header = 'CC: [email protected]';
  12. $header .= 'BCC: [email protected]';
  13. echo $header;
  14. */
  15.  
  16. /*
  17. ARRAY OPERATORS
  18. To compare arrays
  19.  
  20. +       Union           $x + $y     Union of $x and $y
  21. ==      Equality        $x == $y    Returns true if $x & $y have same key/value pairs.
  22. ===     Identity        $x === $y   Returns true if $x & $y have the same key/value pairs in same order and same type
  23. !=      Inequality      $x != $y    Returns true if $x is not equal to $y
  24. <>      Inequality      $x <> $y    Returns true if $x is not equal to $y
  25. !==     Not Identity    $x !== $y     Returns true if $x is not identical to $y
  26.  
  27. $x = array('a' => 'red', 'b' => 'green');
  28. $y = array('c' => 'blue', 'd' => 'orange');
  29.  
  30. var_dump($x !== $y);
  31.  
  32. CONSTANTS
  33. define('COUNTRY_NAME', 'Nepal');
  34. echo COUNTRY_NAME;
  35.  
  36. CONDITIONAL STATEMENTS
  37. 1. If Statement
  38. if (condition) {
  39.     code block
  40. }
  41.  
  42. 2. If Else
  43.     if (condition) {
  44.       this code block runs
  45.     } else {
  46.         this code block runs
  47.     }
  48.  
  49. 3. If Else-If Statement
  50.     if (condition) {
  51.         code
  52.     } elseif (condition) {
  53.         code
  54.     } elseif (condition) {
  55.         code
  56.     } else {
  57.         code
  58.     }
  59.  
  60. $result = 80;
  61. if ($result = 70) {
  62.     echo 'Grade A';
  63. } elseif ($result >= 60) {
  64.     echo 'Grade B';
  65. } else {
  66.     echo 'Pass';
  67. }
  68.  
  69. TERNARY OPERATORS
  70. one line if else
  71. $var = 1;
  72. $var_is_greater_than_two = ($var > 2 ? true : false);
  73. var_dump($var_is_greater_than_two);
  74.  
  75. SWITCH STATEMENTS
  76. */
  77. $num = 'Test Number';
  78. switch ($num) {
  79.     case 'Test Number':
  80.         echo 'One';
  81.         break;
  82.     case 2:
  83.         echo 'Two';
  84.         break;
  85.     case 3:
  86.         echo 'Three';
  87.         break;
  88.     default:
  89.         echo 'No Number';
  90. }
Add Comment
Please, Sign In to add comment