我知道这很容易思考,但不知道如何将其转换为代码。我有两组数组(标题和正文),如下所示:
HEADER
'tfa_1' => string '(First, Middle, Last)' (length=21)
'tfa_10' => string 'Card Type' (length=9)
'tfa_11' => string 'Diners Club' (length=11)
'tfa_12' => string 'MasterCard' (length=10)
'tfa_3' => string 'Last 4 Digits of Card Number' (length=28)
'tfa_127' => string 'Email Address' (length=13)
'tfa_150' => string 'Phone Number' (length=12)
'tfa_156' => string 'What type of phone number is this?' (length=34)
'tfa_157' => string 'Mobile Number' (length=13)
'tfa_158' => string 'Landline Number' (length=15)
'tfa_128' => string 'When is the best time to call you for verification?' (length=51)
BODY
'tfa_1' => string 'Mike' (length=18)
'tfa_10' => string 'MasterCard' (length=10)
'tfa_3' => string '123' (length=4)
'tfa_127' => string 'mike@yahoo.com' (length=22)
'tfa_150' => string '09xxxxxx' (length=11)
'tfa_156' => string 'Mobile Number' (length=13)
我需要它像这样:
'tfa_1' => string 'mike' (length=21)
'tfa_10' => string 'MasterCard' (length=9)
'tfa_11' => string '' (length=11)
'tfa_12' => string '' (length=10)
'tfa_3' => string '123' (length=28)
'tfa_127' => string 'mike@yahoo.com' (length=13)
'tfa_150' => string 'P09xxxxxx' (length=12)
'tfa_156' => string 'Mobile Number' (length=34)
'tfa_157' => string '' (length=13)
'tfa_158' => string '' (length=15)
'tfa_128' => string ''
我试过
$merge = (array_merge($header,$body));
成功但我需要那些$ body没有响应的特定键应该为NULL
答案 0 :(得分:0)
如果密钥存在,则添加值else填充空值..
$data
将满足您的需求。我假设$header
是标题数组,$body
是主体数组。
$data=array();
foreach($header as $key=>$value){
if (array_key_exists($key, $body))
$data[key]=$body[$key];
else
$data[key]="";
}
答案 1 :(得分:0)
首先你可以使用
1
如果要转储$arrayMerge = array_merge($array1, $array2);
,则它包含重复的值。
您可以使用$arrayMerge
我希望它会对你有所帮助。