1. You can convert a two-bit array into two one-dimensional arrays, with no specified key being the default index
How to convert the following two-dimensional array to a one-dimensional array.
Copy CodeThe code is as follows:
$msg = Array (
Array
' id ' = ' 45 ',
' Name ' = ' Jack '
),
Array
' id ' = ' 34 ',
' Name ' = ' Mary '
),
Array
' id ' = ' 78 ',
' Name ' = ' Lili '
),
);
The first method:
Copy CodeThe code is as follows:
foreach ($msg as $k = = $v) {
$ids [] = $id;
$names [] = $name;
}
The second method:
Copy CodeThe code is as follows:
$ids = Array_column ($msg, ' id ');
$names = Array_column ($msg, ' name ');
The above two methods Print_r ($names), the result is:
Copy CodeThe code is as follows:
Array (
[0]=>jack
[1]=>mary
[2]=>lili
)
Note: Array_column (); can have a third parameter, such as $n = Array_column ($msg, ' name ', ' id ');
Print_r ($n); The result is:
Copy CodeThe code is as follows:
Array (
[45]=>jack
[34]=>mary
[78]=>lili
) Thanks: http://www.jb51.net/article/50410.htm
Functions of an array of PHP