Advertisement
RahmanIEN

operator Increment/Decrement

Jun 23rd, 2023 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | Source Code | 0 0
  1. <?php
  2. // Increment
  3. $a = 5;
  4. $a++; // sama dengan $a = $a + 1;
  5. echo $a; // Output: 6
  6.  
  7. // Decrement
  8. $b = 8;
  9. $b--; // sama dengan $b = $b - 1;
  10. echo $b; // Output: 7
  11.  
  12. // Prefix Increment
  13. $c = 10;
  14. echo ++$c; // Output: 11
  15.  
  16. // Prefix Decrement
  17. $d = 7;
  18. echo --$d; // Output: 6
  19.  
  20. // Postfix Increment
  21. $e = 4;
  22. echo $e++; // Output: 4
  23. echo $e;   // Output: 5
  24.  
  25. // Postfix Decrement
  26. $f = 9;
  27. echo $f--; // Output: 9
  28. echo $f;   // Output: 8
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement