The method of using recursive algorithm to iterate an infinite array in PHP

Source: Internet
Author: User
This article mainly introduces the use of recursive algorithm of PHP infinite Traversal array, combined with examples of PHP for one-dimensional arrays, two-dimensional arrays and multi-dimensional irregular array of general traversal techniques, the need for friends can refer to the next

Specific as follows:

<?php//Infinite Traversal Array $a1 = Array ("A", "B", "C"); One-dimensional array $a2 = Array (Array (3, 6), Array ("A", "B", "C")); Two-dimensional array $a3 = Array (Array (5, 4, 444), 2, 7, 6, 8, Array ("W", "D", Array (3, 2, "a"), "s"));  Multidimensional Irregular array function fun ($a) {  foreach ($a as $val) {    if (Is_array ($val)) {///If the key value is an array, the function recursively calls Fun      ($val);    } else {//If the key value is numeric, output      echo "$val <br/>";    }//end if      }//end foreach  }//end fun//fun ($a 1);//fun ($ A2); Fun ($a 3);? >

Output:

55544442768wd32as

The above is the whole content of this article, I hope that everyone's study has helped.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.