$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");
foreach ($citycode as $arr) {
echo $arr.'\\n';
}
saveFile('file.txt',$arr);
我希望file.txt里的内容为:
101010100,101010200,101010300
这个$arr要怎么写?
------解决思路----------------------
<?php
$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");
foreach ($citycode as $arr => $value) {
$citycode[$arr] .= ',';
}
// saveFile('file.txt',$arr);
file_put_contents('file.txt', $citycode);
?>
------解决思路----------------------
这样岂不是更简单
$arr = implode(',', $citycode);
saveFile('file.txt',$arr);
------解决思路----------------------
$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");
saveFile('file.txt',implode(',',$citycode));