自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

案例分析PHP數(shù)組查詢

開發(fā) 后端
PHP隨著發(fā)展,它的功能也逐漸的強(qiáng)大,文章這里單單列舉了關(guān)于PHP數(shù)組查詢代碼分析,希望對大家有幫助。

學(xué)習(xí)PHP數(shù)組時(shí),你可能會(huì)遇到問題,這里將介紹PHP數(shù)組查詢,在這里拿出來和大家分享一下。PHP4.0中共有超過30個(gè)新的數(shù)組相關(guān)函數(shù)。其中很多通用函數(shù)允許你檢查給定數(shù)組中是否存在特定對象、對數(shù)組元素計(jì)數(shù)、增加或刪除元素,或?qū)υ嘏判颉?

#T#如果你有很大的一個(gè)數(shù)組,而所要完成的僅是找出一個(gè)存在的給定值,你可以使用in_array()以返回true 或 false。如下代碼將輸出“Not found in this array”——因?yàn)槟銓⒃?namesArray中尋找一個(gè)并不存在的“Alber ”。你可以對任何數(shù)組添加元素,無論是在已存在數(shù)組的開始或末尾。你也可以使用函數(shù)以創(chuàng)建一個(gè)包含兩個(gè)或多個(gè)數(shù)組元素的新數(shù)組。合并時(shí)每個(gè)數(shù)組將按需要的順序排列。如果你的數(shù)組已經(jīng)有內(nèi)部的排序,你需要對新的合并數(shù)組重排序。

PHP數(shù)組查詢代碼:

  1. /**  
  2. *倒序數(shù)組  
  3. *@paramaInputarray要排序的數(shù)組  
  4. *@param$bystring排序?qū)ο?key為按數(shù)組下標(biāo)排序,value為按值排序  
  5. */  
  6. functionaryReverts($aInput,$by='key'){  
  7. if(!is_array($aInput)){  
  8. returnfalse;  
  9. }  
  10. $res=array();  
  11. $n=count($aInput);  
  12. for($i=0;$i<$n;$i++){  
  13. $tmMax=getMax($aInput,$by);  
  14. print_r($tmMax);  
  15. list($k,$v)=each($tmMax);  
  16. $res[$k]=$v;  
  17. }  
  18. return$res;  
  19. }  
  20.  
  21.  
  22. /**  
  23. *@paramaInputarray要冒溝的數(shù)組  
  24. *@param$bystring排序?qū)ο?key為按數(shù)組下標(biāo)排序,value為按值排序  
  25. */  
  26. functiongetMax(&$aInput,$by){  
  27. $max=null;  
  28. $maxKey=null;  
  29. if($by=='key')  
  30. $tar='k';  
  31. else  
  32. $tar='v';  
  33. foreach($aInputas$k=>$v){  
  34. if($$tar>$max){  
  35. $max=$$tar;  
  36. $maxKey=$k;  
  37. }  
  38. }  
  39. $maxValue=$aInput[$maxKey];  
  40. unset($aInput[$maxKey]);  
  41. returnarray($maxKey=>$maxValue);  
  42. }  
  43.  
  44.  
  45. $list=array('apple'=>300,'orange'=>150,'banana'=>100,'mango'=>330);  
  46. echo'<xmp>';  
  47. print_r(aryReverts($list,'value')); 
責(zé)任編輯:田樹 來源: 博客
相關(guān)推薦

2009-11-18 15:05:56

PHP遞歸數(shù)組

2009-11-16 16:43:24

PHP數(shù)組刪除

2009-11-24 19:40:07

PHP關(guān)聯(lián)數(shù)組查詢結(jié)果

2009-11-16 10:16:24

PHP文件上傳

2009-11-17 15:13:28

PHP數(shù)組

2024-03-05 15:28:38

SQL窗口函數(shù)分頁查詢

2010-01-05 17:59:46

PHP JSON數(shù)組對

2011-07-12 17:06:43

PHP

2009-11-16 16:17:45

PHP數(shù)組排序

2009-11-17 15:07:16

PHP數(shù)組遍歷

2009-11-18 14:11:10

PHP數(shù)組變量

2009-11-25 09:56:06

PHP數(shù)組處理函數(shù)

2009-12-04 14:41:11

PHP數(shù)組變成JSON

2009-11-16 17:35:38

PHP數(shù)組排序

2009-11-25 16:55:45

PHP函數(shù)explod

2009-09-22 11:30:57

2022-10-26 10:15:53

GoFramePHP數(shù)組

2009-11-17 14:33:38

PHP數(shù)組循環(huán)操作

2009-11-16 16:23:10

PHP數(shù)組遍歷

2011-07-05 18:10:14

PHP
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)