我试图转换
$user = array();
$user[] = array("name" => "Jesse James", "email" => "jesse@example.com", "phone" => "212-999-9999");
$user[] = array("name" => "Donald Duck", "email" => "donals@example.com", "phone" => "818-999-9999");
Array ( [0] => Array ( [name] => Jesse James [email] => jesse@example.com [phone] => 212-999-9999 ) [1] => Array ( [name] => Donald Duck [email] => donals@example.com [phone] => 818-999-9999 ) )
但我想将其转换为:
Array ( [name[0]] => Jesse James [email[0]] => jesse@example.com [phone[0]] => 212-999-9999 ) [1] => Array ( [name[1]] => Donald Duck [email[1]] => donals@example.com [phone[1]] => 818-999-9999 )
答案 0 :(得分:0)
请在发布之前格式化您的代码。
$a = array(
"name" => "Jesse James",
"email" => "jesse@example.com",
"phone" => "212-999-9999"
);
$b = array(
"name" => "Donald Duck",
"email" => "donals@example.com",
"phone" => "818-999-9999"
);
print_r(array_merge_recursive($a, $b));
输出:
Array
(
[name] => Array
(
[0] => Jesse James
[1] => Donald Duck
)
[email] => Array
(
[0] => jesse@example.com
[1] => donals@example.com
)
[phone] => Array
(
[0] => 212-999-9999
[1] => 818-999-9999
)
)