php获取数组最后一个元素的方法

最后一个数组元素在php中方法有很多,一个是根据长度来取最大下标值,一个是使用end函数,还一个对数据进行排序之后最下标0即可下面我们一起来看看吧。

$array=array(1,2,3,4,5);  

echo $array[count($array)-1];//计算数组长度,然后获取数组最后一个元素,如果数组中最后一个元素含有非数字键名,结果可能跟预期不符合  

//适用于键名为数字的数组  

echo '<br>';  

echo end($array);//将数组的内部指针指向最后一个单元,适用于所有数组  

rsort($array);//对数组逆向排序,如果数组中含有字母或汉字,结果可能不符合预期,最适用于数字数组

echo $array[0];

删除最后一个元素,代码如下:

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

波比源码 » php获取数组最后一个元素的方法

153 评论

  1. buy avodart pill avodart price zofran 4mg for sale

  2. buy ampicillin 500mg without prescription acillin usa buy erythromycin 250mg pills

  3. tadalafil 40mg gГ©nГ©rique acheter 5mg cialis acheter 25mg du sildenafil

  4. buy prednisone 50 mg cialis sildenafil pills 50mg

  5. order ramipril online cheap azelastine order buy azelastine online

  6. buy buspirone 10mg buspar 10mg oral buy oxybutynin 5mg without prescription

  7. cheap generic cialis prozac usa order sildenafil 50mg

  8. order zyprexa 10mg pills diovan 80mg ca order valsartan 80mg for sale

  9. buy linezolid 600 mg online play online blackjack free casino games no registration no download

  10. order clomid 100mg pills clomiphene uk global poker online

  11. domperidone without prescription flexeril 15mg oral cyclobenzaprine pills

  12. baclofen order toradol sale buy toradol 10mg generic

  13. brand imitrex 25mg avodart pill brand avodart

  14. buy cialis 5mg cialis sale viagra 50mg us

  15. ceftin 500mg canada careprost ca order methocarbamol 500mg pills

  16. pay for term paper stromectol ca ivermectin 9 mg

  17. best poker online real money gambling site tadalafil 10mg over the counter

  18. clarithromycin 250mg tablet antivert canada order meclizine without prescription

  19. poker online games real casino slots real money

  20. professional letter writing services buy an assignment sulfasalazine 500 mg us

  21. order amoxicillin online cheap stromectol pills ivermectin 3mg tablet

  22. buy indocin 75mg without prescription indocin pills cenforce 50mg sale

  23. buy doxycycline 100mg online cheap purchase medrol pills methylprednisolone 16mg without a doctor prescription

  24. simvastatin 10mg for sale buy phenergan sale sildenafil overnight delivery

  25. warfarin online reglan pills brand zyloprim 100mg

  26. where to buy provigil without a prescription buy provigil 200mg oral deltasone

  27. order accutane 20mg without prescription isotretinoin 20mg canada where to buy zithromax without a prescription

  28. purchase synthroid sale clomiphene ca vardenafil pill

  29. buy praziquantel 600mg for sale cheap microzide generic periactin 4 mg

  30. where to buy imitrex without a prescription avodart 0.5mg brand dutasteride drug

  31. order generic flomax 0.2mg buy zofran 8mg generic order spironolactone 100mg without prescription

  32. cymbalta 20mg for sale cymbalta price buy nootropil 800 mg pills

  33. betamethasone 20 gm price buy betnovate 20 gm order itraconazole 100 mg without prescription

  34. cialis tablets usa cialis sales viagra 100mg without prescription

  35. cost of ivermectin lotion buy prednisone deltasone 10mg canada

  36. buy furosemide tablets generic monodox albuterol where to buy

  37. Sex toys https://self-lover.store/ have become an integral part of modern intimate life for many people. Their variety strikes the imagination. In intimate goods stores you can find many different types and models that help diversify your sex life and give pleasure.

  38. oral temovate cost temovate amiodarone 200mg sale

  39. olumiant 4mg cost olumiant 4mg us how to get atorvastatin without a prescription

发表评论

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

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