When learning PHP arrays, you may encounter problems, here will introduce the PHP array query, here to take out and share with you. PHP4.0 has more than 30 new array-related functions. Many of these general functions allow you to check for specific objects in a given array, count arrays of elements, add or delete elements, or sort elements.
If you have a large array, and all you have to do is find a given value that exists, you can use In_array () to return True or false. The following code will output "not found the This array"-because you will find a "Alber" in $namesarray that does not exist. You can add elements to any array, either at the beginning or the end of an existing array. You can also use a function to create a new array that contains two or more arrays of elements. When merging, each array is arranged in the order in which it is needed. If your array already has an internal sort, you need to reorder the new merged array.
PHP Array Query Code:
- /**
- * Reverse Array
- * @paramaInputarray the array to sort
- * @param $bystring Sort objects, key is sorted by array subscript, value is sorted by value
- */
- Functionaryreverts ($aInput, $ by=' key ') {
- if (!is_array ($aInput)) {
- Returnfalse;
- }
- $ Res = Array ();
- $ N = Count ($aInput);
- For ($i=0; $i<$n; $i + +) {
- $ Tmmax = Getmax ($aInput, $by);
- Print_r ($tmMax);
- List ($k, $v) =each ($tmMax);
- $res [$k]= $v;
- }
- Return$res;
- }
- /**
- * @paramaInputarray the array to ditch
- * @param $bystring Sort objects, key is sorted by array subscript, value is sorted by value
- */
- Functiongetmax (& $aInput, $by) {
- $ Max = NULL ;
- $ Maxkey = NULL ;
- if ($by= = ' key ')
- $ Tar = ' K ' ;
- Else
- $ Tar = ' V ' ;
- foreach ($aInputas $k=>$v) {
- if ($ $tar>$max) {
- $ Max =$ $tar;
- $ Maxkey = $k;
- }
- }
- $ MaxValue = $aInput [$maxKey];
- Unset ($aInput [$maxKey]);
- ReturnArray ($maxkey=>$maxValue);
- }
- $ List = Array (' apple ' =>, ' orange ' =>, ' banana ' => , ' mango ' =>330);
- Echo ' <XMP> ';
- Print_r (Aryreverts ($list, ' value '));
http://www.bkjia.com/PHPjc/446541.html www.bkjia.com true http://www.bkjia.com/PHPjc/446541.html techarticle When learning PHP arrays, you may encounter problems, here will introduce the PHP array query, here to take out and share with you. PHP4.0 has more than 30 new array-related functions. Where ...