php中向数组中插入一元素程序代码

本文章这里是一个己排序好的二维数据,我们要向数组中插入一个元素这个保存到数据中后还需要进行排序的哦,代码如下:

  1. <?php  
  2. /**  
  3. * 逆序二维数组插入一元素  
  4.  
  5. * @author WadeYu  
  6. * @date 2012-05-30  
  7. */  
  8. $aSorted = array(  
  9. array(1, 100),  
  10. array(2, 90),  
  11. array(3, 80),  
  12. array(4, 70),  
  13. array(5, 60),  
  14. array(6, 50),  
  15. array(7, 40),  
  16. array(8, 40),  
  17. array(9, 40),  
  18. array(10, 20),  
  19. );  
  20. $aInsert = array(11, 40);  
  21. $maxCmpIdx = 0;  
  22. $cnt = 0;  
  23. $maxCnt = 10;  
  24. foreach ($aSorted as $idx => $arr){  
  25. if ($arr[0] == $aInsert[0]){  
  26. $maxCmpIdx = $idx;  
  27. }  
  28. $cnt++;  
  29. }  
  30. if ( !$maxCmpIdx){  
  31. $maxCmpIdx = $cnt++;  
  32. }  
  33. $aSorted[$maxCmpIdx] = $aInsert;  
  34. for ($i = $maxCmpIdx$i > 0; $i–){  
  35. if ($aSorted[$i][1] > $aSorted[$i-1][1]){  
  36. $aTmp = $aSorted[$i-1];  
  37. $aSorted[$i-1] = $aSorted[$i];  
  38. $aSorted[$i] = $aTmp;  
  39. continue ;  
  40. }  
  41. break;  
  42. }  
  43. for ($i = $cnt$i > $maxCnt$i–){  
  44. unset($aSorted[$i-1]);  
  45. }  
  46. print_r($aSorted); 

在数组中插入元素的方法有很多,这里只介绍了一种,有需要了解更多的朋友可到本站搜索。

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

波比源码 » php中向数组中插入一元素程序代码

82 评论

  1. order suhagra 50mg online cheap cost aurogra order estradiol sale

  2. lamictal 200mg without prescription purchase tretinoin tretinoin gel tablet

  3. order tadalafil 20mg pill tadalis ca oral voltaren 100mg

  4. buy modafinil 100mg Best price cialis acetazolamide 250mg over the counter

  5. buy molnunat 200mg generic lansoprazole ca lansoprazole 30mg oral

  6. chloroquine pill generic aralen baricitinib medication

  7. cialis next day cialis 40mg usa order viagra 100mg generic

  8. cheap triamcinolone clarinex price desloratadine price

  9. that roulette best casino blackjack games

  10. fluconazole sale pfizer viagra order sildenafil 100mg online cheap

  11. term papers writing service buy assignments ivermectin 3mg stromectol

  12. sildenafil pharmacy cheap estradiol order lamictal generic

  13. order prednisone 40mg pills oral prazosin mebendazole us

  14. buy generic tadacip buy diclofenac 50mg order indocin 75mg without prescription

  15. purchase tiotropium bromide for sale hytrin cost cheap hytrin 5mg

  16. order tadalafil 20mg generic Cialis sales order cialis 20mg generic

  17. nifedipine 10mg without prescription adalat 10mg uk order allegra 180mg online

  18. buy amoxicillin 1000mg pills oral amoxicillin ivermectin cream 1

  19. purchase dapoxetine online dapoxetine cost buy domperidone 10mg generic

  20. purchase esomeprazole sale cheap lasix order furosemide 100mg without prescription

发表评论

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

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