早上好,以下数组想知道如何将它们组合成一个数组吗?
Array(
[name_option] => Tamanho
[name_option_value] => Grande) Array(
[name_option] => Cor
[name_option_value] => Amarelo) Array(
[name_option] => Tamanho
[name_option_value] => Medio) Array (
[name_option] => Cor
[name_option_value] => Azul) Array (
[name_option] => Tamanho
[name_option_value] => Pequeno ) Array(
[name_option] => Cor
[name_option_value] => Verde )
答案 0 :(得分:0)
$a1=array("red","green");
$a2=array("blue","yellow");
$new_array = array_merge($a1,$a2);
print_r($new_array);
的更多详情
答案 1 :(得分:0)
你可以将它们组合成一个多维数组:
<?php
$a = [];
$a[] = [
'name_option' => 'Tamanho',
'name_option_value' => 'Grande'
];
$a[] = [
'name_option' => 'Cor',
'name_option_value' => 'Amarelo'
];
$a[] = [
'name_option' => 'Tamanho',
'name_option_value' => 'Medio'
];
$a[] = [
'name_option' => 'Cor',
'name_option_value' => 'Azul'
];
$a[] = [
'name_option' => 'Tamanho',
'name_option_value' => 'Pequeno'
];
$a[] = [
'name_option' => 'Cor',
'name_option_value' => 'Verde'
];
print_r($a);
结果:
Array
(
[0] => Array
(
[name_option] => Tamanho
[name_option_value] => Grande
)
[1] => Array
(
[name_option] => Cor
[name_option_value] => Amarelo
)
[2] => Array
(
[name_option] => Tamanho
[name_option_value] => Medio
)
[3] => Array
(
[name_option] => Cor
[name_option_value] => Azul
)
[4] => Array
(
[name_option] => Tamanho
[name_option_value] => Pequeno
)
[5] => Array
(
[name_option] => Cor
[name_option_value] => Verde
)
)
或重命名密钥(例如添加索引)以防止覆盖