recursive - 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.
Result of php executing
Full code of recursive.php
- <?php
- $rowData = [
- ['Buffalo', 'Tampa Bay', -7, 'favorite', 0, 46],
- ['Minnesota', 'Tennessee', 3, 'favorite', 1, 33],
- ['Green Bay', 'Cincinnati', 3, 'favorite', 1, 33],
- ['Jacksonville Bay', 'Buffalo', 4, 'underdog', 1, 54],
- ];
- recursiveArray($rowData);
- print_r($rowData);
- # A recursive function to traverse the $rowData array
- function recursiveArray(array $rowData)
- {
- foreach ($rowData as $key => $hitElement) {
- # If there is a element left
- if (is_array($hitElement)) {
- # call recursive structure to parse the $rowData
- recursiveArray($hitElement);
- } else {
- if ($key == 4) {
- switch($hitElement) {
- case 1:
- echo 'Calling fn();' . PHP_EOL;
- break;
- case 0:
- echo 'Calling differentfn();' . PHP_EOL;
- break;
- }
- }
- }
- }
- }