"101010100","海淀"=>"101010200","朝阳"=>"101010300"); foreach ($citycode as $arr) { echo "/> "101010100","海淀"=>"101010200","朝阳"=>"101010300"); foreach ($citycode as $arr) { echo ">

Home  >  Article  >  Backend Development  >  foreach 输出遇到的有关问题,求各位老师解决

foreach 输出遇到的有关问题,求各位老师解决

WBOY
WBOYOriginal
2016-06-13 12:18:05998browse

foreach 输出遇到的问题,求各位老师解决
$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");

foreach ($citycode as $arr) {

echo $arr.'\\n';
}
saveFile('file.txt',$arr);

我希望file.txt里的内容为:

101010100,101010200,101010300


这个$arr要怎么写?
------解决思路----------------------

<br /><?php<br /><br />$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");<br /><br />foreach ($citycode as $arr => $value) {<br />    $citycode[$arr] .= ',';<br />}<br />// saveFile('file.txt',$arr);<br />file_put_contents('file.txt', $citycode);<br /><br />?><br />

------解决思路----------------------
这样岂不是更简单
$arr = implode(',', $citycode);<br />saveFile('file.txt',$arr);

------解决思路----------------------
<br />$citycode = array("北京"=>"101010100","海淀"=>"101010200","朝阳"=>"101010300");<br />saveFile('file.txt',implode(',',$citycode));<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn