Advertisement
RahmanIEN

Operator Null Coalescing

Jun 23rd, 2023 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | Source Code | 0 0
  1. <?php
  2. // Contoh 1
  3. $name = "John Doe";
  4. $username = $name ?? "Guest";
  5. echo $username; // Output: John Doe
  6.  
  7. // Contoh 2
  8. $score = null;
  9. $finalScore = $score ?? 0;
  10. echo $finalScore; // Output: 0
  11.  
  12. // Contoh 3
  13. $city = null;
  14. $defaultCity = "Unknown";
  15. $selectedCity = $city ?? $defaultCity;
  16. echo $selectedCity; // Output: Unknown
  17.  
  18. // Contoh 4
  19. $language = "PHP";
  20. $programmingLanguage = $language ?? "JavaScript";
  21. echo $programmingLanguage; // Output: PHP
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement