php涓殑foreach寰幆
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php涓殑foreach寰幆相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%b8%80%e4%b8%aa' title='涓€涓?>涓€涓?/a> col 鍔炵悊 鏁扮粍 浣跨敤鏂规硶 涓ょ color 甯哥敤 涓嬫爣
php涓殑foreach璇彞锛屽父鐢ㄤ簬閬嶅巻鏁扮粍銆?/strong>
foreach涓€鑸湁涓ょ浣跨敤鏂瑰紡锛?/p>
(1)鍙彇鏁扮粍鐨勫€硷紝涓嶅彇鏁扮粍鐨勪笅鏍囷紱
(2)鍙栨暟缁勫€硷紝鍚屾椂涔熷彇鏁扮粍鐨勪笅鏍?/p>
浠ヤ笅闈㈢殑渚?鍜屼緥2鏉ヨВ閲婂叾鐢ㄦ硶锛?/p>
渚?锛氬彧鍙栧€硷紝涓嶅彇涓嬫爣
$member=array( 鈥?/span>201201鈥?/span>=>鈥?/span>Tom鈥?/span>, 鈥?/span>201203鈥?/span>=>鈥?/span>Jack鈥?/span>, 鈥?/span>201211鈥?/span>=>鈥?/span>James鈥?/span>, 鈥?/span>201306鈥?/span>=>鈥?/span>Martin鈥?/span>, 鈥?/span>201605鈥?/span>=>鈥?/span>Lucy鈥?/span>, 鈥?/span>201612鈥?/span>=>鈥?/span>Kim鈥?/span>,);//鏂板缓涓€涓暟缁勶紝涓斿寘鍚笉鍚岀殑涓嬫爣 echo "璇ュ晢搴楃殑浼氬憳鏈?/span>"; foreach($member as $name){ echo $name.","; }; 杈撳嚭缁撴灉涓猴細璇ュ晢搴楃殑浼氬憳鏈塗om,Jack,James,Martin,Lucy,Kim, 鎵€浠ワ紝浣跨敤foreach涓斿彧鍙栨暟缁勭殑鍊兼椂鍏朵娇鐢ㄦ柟娉曚负锛? <?php foreach(鏁扮粍 as 涓嬫爣){ //鎵ц璇彞 }
(2)鏃㈠彇鏁扮粍鍊硷紝鍙堝彇鏁扮粍涓嬫爣
$member=array( 鈥?/span>201201鈥?/span>=>鈥?/span>Tom鈥?/span>, 鈥?/span>201203鈥?/span>=>鈥?/span>Jack鈥?/span>, 鈥?/span>201211鈥?/span>=>鈥?/span>James鈥?/span>, 鈥?/span>201306鈥?/span>=>鈥?/span>Martin鈥?/span>, 鈥?/span>201605鈥?/span>=>鈥?/span>Lucy鈥?/span>, 鈥?/span>201612鈥?/span>=>鈥?/span>Kim鈥?/span>,);//鏂板缓涓€涓暟缁勶紝涓斿寘鍚笉鍚岀殑涓嬫爣 foreach($member as $num=>$name){ echo $name."鐨勪細鍛樺姙鐞嗘湀浠芥槸".$num."<br>"; }; 姝ゆ椂鐨勮緭鍑虹粨鏋滀负锛? Tom鐨勪細鍛樺姙鐞嗘湀浠芥槸201201 Jack鐨勪細鍛樺姙鐞嗘湀浠芥槸201203 James鐨勪細鍛樺姙鐞嗘湀浠芥槸201211 Martin鐨勪細鍛樺姙鐞嗘湀浠芥槸201306 Lucy鐨勪細鍛樺姙鐞嗘湀浠芥槸201605 Kim鐨勪細鍛樺姙鐞嗘湀浠芥槸201612 鎵€浠ワ紝浣跨敤foreach鍚屾椂鍙栨暟缁勭殑鍊煎拰鏁扮粍鐨勪笅鏍囨椂鍏朵娇鐢ㄦ柟娉曚负锛? <?php foreach(鏁扮粍 as 涓嬫爣=>鍊?{ //鎵ц璇彞 }
以上是关于php涓殑foreach寰幆的主要内容,如果未能解决你的问题,请参考以下文章
Hyperf 鍙戝竷 v1.1.13 鐗堟湰 | 浼佷笟绾х殑 PHP 寰湇鍔′簯鍘熺敓鍗忕▼妗嗘灦