Case study: PHP array query. When learning PHP arrays, you may encounter problems. here we will introduce PHP array queries and share them with you here. PHP4.0 contains more than 30 new array-related functions. When learning PHP arrays, you may encounter problems. here we will introduce PHP array queries and share them with you. PHP4.0 contains more than 30 new array-related functions. Many common functions allow you to check for specific objects in a given array, count array elements, add or delete elements, or sort elements.
If you have a large array and all you need to do is find an existing given value, you can use in_array () to return true or false. The following code outputs "Not found in this array" -- because you will find an existing "Alber" in $ namesArray ". You can add elements to any array, whether at the beginning or end of an existing array. You can also use a function to create a new array containing two or more array elements. During merging, each array is arranged in the required order. If your array already has internal sorting, you need to re-sort the new merged array.
PHP array query code:
- /**
- * Inverted array
- * @ ParamaInputarray the array to be sorted
- * @ Param $ bystring: sorting objects, keys are sorted by array subscript, and values are 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, $ );
- Print_r ($ tmMax );
- List ($ k, $ v) = each ($ tmMax );
- $ Res [$ k] = $ v;
- }
- Return $ res;
- }
-
-
- /**
- * @ ParamaInputarray array
- * @ Param $ bystring: sorting objects, keys are sorted by array subscript, and values are sorted by value
- */
- FunctiongetMax (& $ aInput, $ ){
- $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' =>300, 'Orange '=>150, 'bana' =>100, 'Mango' =>330 );
- Echo'<Xmp>';
- Print_r (aryReverts ($ list, 'value '));
Bytes. PHP4.0 contains more than 30 new array-related functions. Where...