array test - 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 array test.php

  1. <?php
  2.  
  3. //given an array like this:
  4.  
  5. $categories = [
  6.     'Mobile' => [
  7.         'Phones' => [
  8.             'Android phones',
  9.             'Apple iPhone'
  10.         ],
  11.         'Tablets' => [
  12.             'Android tablets',
  13.             'Apple iPad'
  14.         ],
  15.     ],
  16.     'Photo & Video' => [
  17.         'Action Cameras' => [
  18.             'GoPro',
  19.             'Sony'
  20.         ],
  21.         'Storage & memory' => [
  22.             'SD Cards',
  23.             'USBs'
  24.         ]
  25.     ],
  26.     'Gaming' => [
  27.         'Playstation' => [
  28.             'Playstation 4' => [
  29.                 'Playstation 4 Games',
  30.                 'Playstation 4 Consoles'
  31.             ],
  32.             'Playstation VR' => [
  33.                 'Playstation VR Games',
  34.                 'Playstation VR Accessories'
  35.             ]
  36.         ],
  37.         'Xbox One' => [
  38.             'Xbox One Games'
  39.         ]
  40.     ],
  41. ];
  42.  
  43. /*
  44. Output a tree/sitemap like this:
  45.  
  46. Mobile
  47.   Phones
  48.     Android phones
  49.     Apple iPhone
  50.   Tablets
  51.     Android tablets
  52.     Apple iPad
  53. Photo & Video
  54.   Action Cameras
  55.     GoPro
  56.     Sony
  57.   Storage & memory
  58.     SD Cards
  59.     USBs
  60. Gaming
  61.   Playstation
  62.     Playstation 4
  63.       Playstation 4 Games
  64.       Playstation 4 Consoles
  65.     Playstation VR
  66.       Playstation VR Games
  67.       Playstation VR Accessories
  68.   Xbox One
  69.     Xbox One Games
  70. */
File Description
  • array test
  • PHP Code
  • 09 Jul-2021
  • 1.25 Kb
You can Share it: