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