<?php
echo '<pre>';
$directnames = array("LN"=>"ListingId","LAG"=>"AgentCode","ST"=>"MlsStatus","LP"=>"ListPrice","PIC"=>"PhotosCount");
$result = array("LN"=>"129_551453","LAG"=>"2.50","ST"=>"3.00","LP"=>"Ferndale","PIC"=>"359900.00");
$directnames_getkeys = array_keys($directnames);
$result_getkeys = array_keys($result);
$merge_keys = array_intersect($directnames_getkeys,$result_getkeys);
$assigning = array();
foreach($merge_keys as $preparevalues){
foreach($directnames[$preparevalues] as $keys){
echo $assigning[$keys] = $result[$preparevalues];
}
}
echo '</pre>';
?>
預期輸出:PHP分配一個數組的值作爲一個密鑰另一個數組的值,如果兩個陣列密鑰匹配
array(
"ListingId"=>"129_551453",
"AgentCode"=>"2.50",
"MlsStatus"=>"3.00",
"ListPrice"=>"Ferndale",
"PhotosCount"=>"359900.00"
)
是什麼問題? – elibyy
它說,它是一個未聲明的變量或參數傳遞給'$ directnames'的第二個'foreach'行,您可以在其中清楚地看到它。 – Neocortex
當我運行它時,我得到警告,在第16行說警告:爲foreach()提供的無效參數,這是因爲$ directnames [$ preparevalues]是一個字符串,而不是數組 – elibyy