3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $tree = '[{"title":"Dashboard","folder":true,"hideCheckbox":true,"expanded":true,"children":[{"title":"Comenzi","folder":true,"hideCheckbox":true,"expanded":false,"children":[{"title":"create","key":"2","selected":false,"children":[]},{"title":"delete","key":"5","selected":false,"children":[]},{"title":"list","key":"1","selected":false,"children":[]},{"title":"read","key":"3","selected":false,"children":[]},{"title":"update","key":"4","selected":false,"children":[]}]},{"title":"Comisioane","folder":true,"hideCheckbox":true,"expanded":true,"children":[{"title":"Brute","folder":true,"hideCheckbox":true,"expanded":false,"children":[{"title":"create","key":"18","selected":false,"children":[]},{"title":"delete","key":"21","selected":false,"children":[]},{"title":"list","key":"17","selected":false,"children":[]},{"title":"read","key":"19","selected":false,"children":[]},{"title":"update","key":"20","selected":false,"children":[]}]},{"title":"Nete","folder":true,"hideCheckbox":true,"expanded":false,"children":[{"title":"create","key":"23","selected":false,"children":[]},{"title":"delete","key":"26","selected":false,"children":[]},{"title":"list","key":"22","selected":false,"children":[]},{"title":"read","key":"24","selected":false,"children":[]},{"title":"update","key":"25","selected":false,"children":[]}]},{"title":"allowed categories","key":"28","selected":false,"children":[]}]},{"title":"Produse","folder":true,"hideCheckbox":true,"expanded":false,"children":[{"title":"allowed categories","key":"27","selected":false,"children":[]},{"title":"create","key":"7","selected":false,"children":[]},{"title":"delete","key":"10","selected":false,"children":[]},{"title":"list","key":"6","selected":false,"children":[]},{"title":"read","key":"8","selected":false,"children":[]},{"title":"update","key":"9","selected":false,"children":[]}]},{"title":"RMA","folder":true,"hideCheckbox":true,"expanded":false,"children":[{"title":"awb","key":"16","selected":false,"children":[]},{"title":"create","key":"12","selected":false,"children":[]},{"title":"delete","key":"15","selected":false,"children":[]},{"title":"list","key":"11","selected":false,"children":[]},{"title":"read","key":"13","selected":false,"children":[]},{"title":"update","key":"14","selected":false,"children":[]}]}]}]'; $array = json_decode($tree); $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($tree)); foreach ($iterator as $key => $value) { echo $key; continue; }
based on XQD7L
Output for 7.0.20, 7.1.5 - 7.2.0
Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object in /in/f19a2:4 Stack trace: #0 /in/f19a2(4): ArrayIterator->__construct('[{"title":"Dash...') #1 {main} thrown in /in/f19a2 on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.6, 7.1.0
Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object, using empty array instead in /in/f19a2:4 Stack trace: #0 /in/f19a2(4): ArrayIterator->__construct('[{"title":"Dash...') #1 {main} thrown in /in/f19a2 on line 4
Process exited with code 255.
Output for 5.3.17 - 5.6.28
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /in/f19a2:4 Stack trace: #0 /in/f19a2(4): ArrayIterator->__construct('[{"title":"Dash...') #1 {main} thrown in /in/f19a2 on line 4
Process exited with code 255.