How does php traverse a complex multi-dimensional array?

Source: Internet
Author: User
How does php traverse a complex multi-dimensional array, such as an array without any regularity? How does php traverse it? PHPcode $ arrarray (array (val1, val2, val3), aa, bb), php, apache, array (hello, world )); ------ solution ----------------- how php traverses a complex multi-dimensional array
For example, how can we traverse an array without any regularity?
PHP code
  $ Arr = array ('val1', 'val2', 'val3'), 'AA', 'BB'), 'php', 'Apache ', array ('hello', 'World '));


------ Solution --------------------
What do you want to do after traversing? Recursive processing is supported.
PHP code
// As the callback function. The parameter will not be an array function doSomething ($ value) {echo $ value;} function look (array $ array) {foreach ($ array as $ value) {// if it is still an array, then continue traversing if (is_array ($ value) look ($ value); else call_user_func ('dosomething ', $ value );}}

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.