【发布时间】:2013-05-16 22:48:56
【问题描述】:
我有 2 个数组
$array1 = array(
['2013-05-01']=>'test',
['2013-05-02']=>'testing',
['2013-05-03']=>'working',
['2013-05-04']=>'future test');
$array2 = array(
['2013-05-01']=>'1',
['2013-05-02']=>'done',
['2013-05-03']=>'code',
['2013-05-05']=>'release');
我想加入这些数组,这样输出就是
$result = array(
['2013-05-01']=>'test 1',
['2013-05-02']=>'testing 2',
['2013-05-03']=>'working code',
['2013-05-04']=>'future test',
['2013-05-05']=>'release')
我试过 $result = $array1 + array2; array_merge() , array_combine() 都没有给出正确的结果。
你能帮帮我吗?
【问题讨论】:
-
您需要编写自己的代码来执行此操作。没有内置函数。
-
你的意思是使用foreach循环?
-
令我惊讶的是,人们期望 PHP 有一个内置函数,适用于初学者应该能够毫不费力地解决的每一个场景。
-
function array_join($arr1, $arr2) {return array(['2013-05-01']=>'test 1', ['2013-05-02']=>'testing 2',['2013-05-03']=>'working code');}- 只是搞砸了;) -
您给定的代码甚至无法正确编译。