Switch function - Tank Alias - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: Switch function - Tank Alias fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of Switch function - Tank Alias.php

  1. <?php
  2. function tankAlias(&$tank) {
  3.     switch ($tank["country"]) {
  4.         case "Russia":
  5.             $tank["alias"] = "Soviet";
  6.             break;
  7.         case "Germany":
  8.             $tank["alias"] = "German";
  9.             break;
  10.         case "USA":
  11.             $tank["alias"] = "American";
  12.             break;
  13.         default:
  14.             $tank["alias"] = NULL;
  15.     }
  16. }
  17.  
  18. $tank1 = ['name'=>'T-34', 'country'=>'Russia'];
  19. $tank2 = ['name'=> 'Tiger', 'country'=>'Germany'];
  20. $tank3 = ['name'=> 'Churchill', 'country'=>'UK'];
  21.  
  22. tankAlias($tank1);
  23. print_r($tank1);
  24. echo "\n";
  25. tankAlias($tank3);
  26. print_r($tank3);
File Description
  • Switch function - Tank Alias
  • PHP Code
  • 23 May-2020
  • 603 Bytes
You can Share it: