Home  >  Article  >  Backend Development  >  PHP one-dimensional array to two-dimensional array method example code

PHP one-dimensional array to two-dimensional array method example code

怪我咯
怪我咯Original
2017-07-11 16:50:272676browse

You can use subscript variables in the program, which means that the entirety of these variables is an array, and the data type of each variable in the array is the same. When each element in the array has only one subscript, such an array is called One-dimensional array.

One-dimensional array is a single-structured array composed of numbers arranged in a simple sorting structure. One-dimensional arrays are the most basic arrays in computer programs. Two-dimensional and multidimensional arrays can be regarded as generated by multiple superpositions of one-dimensional arrays.

Two-dimensional array is essentially an array with an array as an array element, that is, an "array of arrays".

This article mainly introduces the method of converting one-dimensional array to two-dimensional array in PHP. It analyzes the skills of operating arrays in PHP with examples. It has certain For reference value, friends in need can refer to

This article describes the method of converting a one-dimensional array to a two-dimensional array in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

<?php 
$asr[1] = array("a","b","c","d");
$asr[2] = array("a","b","c","d");
$asr[3] = array("a","b","c","d");
$newarray = array();
foreach($asr as $a)
{
$newarray[] = $a;
}
print_r($newarray);
?>

The above is the detailed content of PHP one-dimensional array to two-dimensional array method example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn