sdfsdf - 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.



Your result can be seen below.

Result of php executing





Full code of sdfsdf.php

  1. <?php
  2.  
  3. $a = json_decode('[{"id":"2","name":"Canada"},{"id":"19","name":"Bahrain"},{"id":"36","name":"Bulgaria"},{"id":"53","name":"Congo, Republic of the"},{"id":"70","name":"Eritrea"},{"id":"87","name":"Greenland"},{"id":"104","name":"Iran"},{"id":"121","name":"Lebanon"},{"id":"138","name":"Mauritania"},{"id":"155","name":"New Zealand"}]', true);
  4.  
  5. $b = json_decode('[{"id":"2","cn":"CA"},{"id":"7","cn":"AS"},{"id":"12","cn":"AG"},{"id":"17","cn":"AT"},{"id":"22","cn":"BY"},{"id":"27","cn":"BT"},{"id":"32","cn":"BR"},{"id":"37","cn":"BF"},{"id":"42","cn":"CV"},{"id":"47","cn":"CN"},{"id":"52","cn":"CD"},{"id":"57","cn":"HR"},{"id":"62","cn":"DJ"},{"id":"67","cn":"EG"},{"id":"72","cn":"ET"},{"id":"77","cn":"FR"},{"id":"82","cn":"GE"},{"id":"87","cn":"GL"},{"id":"92","cn":"GN"},{"id":"97","cn":"VA"}]
  6. ', true);
  7.  
  8. //  написать функцию которая покажет id, name из массива $a, для тех id которые отсутсвуют в массиве $b
  9.  
  10.  
  11. echo showInfo($a, $b);
  12.  
  13. function showInfo(array $a, array $b) : string {
  14.     $arr = [];
  15.  
  16.     foreach ($b as $key => $val) {
  17.         $arr['$key'] = $val; 
  18.     }
  19.     
  20.     $str = '';
  21.     
  22.     foreach ($a as $key => $val) {
  23.         if(!isset($arr[$key])) { 
  24.             $str .= $val['id'].' '.$val['name']. "\n";
  25.         }    
  26.     }    
  27.     
  28.     return "$str";
  29. }
  30.  
  31.     
  32.    
File Description
  • sdfsdf
  • PHP Code
  • 29 Aug-2023
  • 1.33 Kb
You can Share it: