A simple implementation method of PHP multidimensional array to one-dimensional array, _php tutorial

Source: Internet
Author: User

A simple implementation method of PHP multidimensional array to one-dimensional array,


This paper introduces a simple implementation method of PHP multidimensional array to one-dimensional array. Share to everyone for your reference, as follows:

The PHP language itself does not have a function of converting a multidimensional array into a one-dimensional array, but we can write a PHP function ourselves to implement the function of turning multidimensional into one dimension.

The use of recursion, simple rough, the entire function body 9 lines of code to achieve this function, PHP code is as follows:

$multi = Array (Array (      ' wo ',      ' Shi '),    ' php '  ),  ' Cheng ',  Array (    Array (      ' Xu ',      ' yuan ',    )  ),  '! '); $multi = Arrtoone ($multi);p Rint_r ($multi), function Arrtoone ($multi) {  $arr = array ();  foreach ($multi as $key = + $val) {    if (Is_array ($val)) {      $arr = Array_merge ($arr, Arrtoone ($val));    } el SE {      $arr [] = $val;    }  }  return $arr;}

The effect after execution:

Array ([0] = wo [1] = shi [2] = + php [3] = Cheng [4] = Xu [5] = yuan [6] = =!)

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Php method for sorting two-dimensional arrays by specified key values
    • How PHP deletes repeating elements in an array
    • PHP submit Post Array parameter example analysis
    • PHP Array function array_key_exists () Summary
    • PHP Multidimensional Array Traversal method (2 implementation methods)
    • A summary of some common functions of increment, delete and interpolation of logarithm groups in PHP
    • Explain the definition of PHP arrays and how to create them
    • Random merging of arrays and sorting based on PHP implementation (original sort)
    • A method for iterating through multidimensional arrays in PHP

http://www.bkjia.com/PHPjc/1084558.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084558.html techarticle A simple implementation method of PHP multidimensional array to one-dimensional array, this paper describes the simple implementation of PHP multidimensional array to one-dimensional array. Share to everyone for your reference, as follows: P ...

  • 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.