How to convert the following two-dimensional array to a one-dimensional array.
Copy the Code code as follows:
$msg = Array (
Array
' id ' = ' 45 ',
' Name ' = ' Jack '
),
Array
' id ' = ' 34 ',
' Name ' = ' Mary '
),
Array
' id ' = ' 78 ',
' Name ' = ' Lili '
),
);
The first method:
Copy the Code code as follows:
foreach ($msg as $k = = $v) {
$ids [] = $id;
$names [] = $name;
}
The second method:
Copy the Code code as follows:
$ids = Array_column ($msg, ' id ');
$names = Array_column ($msg, ' name ');
The above two methods Print_r ($names), the result is:
Copy the Code code 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 the Code code as follows:
Array (
[45]=>jack
[34]=>mary
[78]=>lili
)
http://www.bkjia.com/PHPjc/776761.html www.bkjia.com true http://www.bkjia.com/PHPjc/776761.html techarticle How to convert the following two-dimensional array to a one-dimensional array. Copy the code as follows: $msg = array (' id ' = ' * ', ' name ' = ' Jack '), array (' id ' = ' {') ', ' name ' = ' Mary '), array (' id ' = ' + ',...