php foreach 循环遍历数组方法

foreach 语句用于循环遍历数组.每进行一次循环,当前数组元素的值就会被赋值给 value 变量(数组指针会逐一地移动) – 以此类推,语法如下:

  1. foreach (array as value) 
  2.     code to be executed; 

下面的例子示范了一个循环,这个循环可以输出给定数组的值:

  1. <html> 
  2. <body> 
  3. <?php 
  4. $arr=array("one""two""three"); 
  5. foreach ($arr as $value
  6.   echo "value: " . $value . "<br />"
  7. ?> 
  8. </body> 
  9. </html> 

下面详细看一下详细说明:

  1. foreach ($array as &$row) {  
  2. $row = explode('/'$row);  
  3. }  
  4. foreach ($array as $row) {  
  5. //do something  

这么写,在第二个循环会出逻辑错误,加入第二个循环中do something的地方是输出$row,循环到最后一个的时候的输出是倒数第二个元素,而不是最后一个,要这么写:

  1. foreach ($array as &$row) {  
  2. $row = explode('/'$row);  
  3. }  
  4. unset($row);  
  5. foreach ($array as $row) {  
  6. //do something  

或者第一个循环这么写,代码如下:

  1. foreach ($array as $key => $row) {  
  2. $array[$key] = explode('/'$row);  
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php foreach 循环遍历数组方法

132 评论

  1. order fildena generic order robaxin robaxin 500mg generic

  2. cialis 40mg sans ordonnance en france acheter du cialis sildenafil 200mg comprimГ©

  3. purchase molnupiravir for sale naproxen usa lansoprazole 15mg oral

  4. order salbutamol 100mcg sale protonix brand buy viagra 50mg for sale

  5. itraconazole 100 mg cost sporanox uk cheap tindamax

  6. dapoxetine online buy buy priligy purchase levothyroxine for sale

  7. buy cialis for sale inderal price order clopidogrel 75mg generic

  8. cialis drug oral cialis 5mg ciprofloxacin over the counter

  9. sildenafil 50mg cost tadalafil otc order generic tadalafil 10mg

  10. cefuroxime cost robaxin for sale buy methocarbamol 500mg without prescription

  11. sildenafil pills 100mg buy estrace lamictal brand

  12. viagra pills tadalafil otc buy cialis online safely

  13. purchase tretinoin generic tadalis 20mg usa buy generic avanafil

  14. buy priligy 30mg generic avana 200mg usa domperidone online buy

  15. buy ropinirole without prescription trandate 100mg cost buy trandate 100 mg generic

  16. order cialis 40mg online cheap us levitra cheapest ed pills

  17. modafinil 200mg price order lisinopril buy metoprolol 100mg sale

  18. продажа дебетовых карт

  19. purchase sildenafil generic viagra 200 mg buy tadalafil 5mg without prescription

  20. cymbalta and tramadol cymbalta or zoloft duloxetine side effects elderly discontinuation

  21. buy fluconazole 100mg without prescription acillin where to buy buy ciprofloxacin pills

  22. buy generic estradiol prazosin 2mg sale buy minipress without a prescription

  23. order furosemide 100mg sale furosemide drug order albuterol 4mg generic

发表评论

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡