RecursiveArrayIterator - 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 RecursiveArrayIterator.php

  1. <?php
  2.  
  3. $hit = [];
  4.  
  5. $accountFieldsToRemove = [
  6.     'first_name',
  7.     'last_name',
  8.     'mail',
  9.     'name',
  10. ];
  11.  
  12. $iterator = new RecursiveArrayIterator($hit);
  13. traverseArray($accountFieldsToRemove, $iterator);
  14.  
  15.  
  16. function traverseArray(array $accountFieldsToRemove, RecursiveArrayIterator $iterator)
  17.     {
  18.         while ($iterator->valid()) {
  19.             if ($iterator->hasChildren()) {
  20.                 traverseArray($accountFieldsToRemove, $iterator->getChildren());
  21.             } else {
  22.  
  23.  
  24.                 if (in_array($iterator->key(), $accountFieldsToRemove)) {
  25.                     echo "#{$iterator->key()} - {$iterator->current()}\r\n";
  26.                     //$iterator->offsetUnset($iterator->key());
  27.                 }
  28.             }
  29.             $iterator->next();
  30.         }
  31.     }
  32.  
File Description
  • RecursiveArrayIterator
  • PHP Code
  • 23 Sep-2022
  • 779 Bytes
You can Share it: