Array Manipulation Classes _php tutorial

Source: Internet
Author: User
     Removeempty (&,=(  =((:: Removeempty ([=((== ''([([] =1, ' value ' = ' 1-1 '), * array (' id ' = + 2, ' value ' = ' 2-1 '), *); * $values = Arrayhelper::getcols ($rows, ' value '); * * Dump ($values); *//output result is *//Array (*//' 1-1 ', *//' 2-1 ', *//) * @endcode * * @param array $arr Data source * @param string $col the key to query * * @return array containing all values for the specified key  Getcols (,=(  (([[] =[ 1, ' value ' = ' 1-1 '), * array (' id ' = + 2, ' value ' = ' 2-1 '), *); * $hashmap = Arrayhelper::tohashmap ($rows, ' id ', ' value '); * * Dump ($HASHMAP); *//output result is *//Array (*///1 = ' 1-1 ', *//2 = ' 2-1 ', *//) * @endcode * * If you omit $valueField parameter, the result of the conversion is each item containing all the data The array. * Usage 2: * @code php * $rows = Array (* Array (' id ' = + 1, ' value ' = ' 1-1 '), * array (' id ' = 2, ' value ' = ' 2-1 '), * ); * $hashmap = Arrayhelper::tohashmap ($rows, ' id '); * * Dump ($HASHMAP); *//output result is *//Array (*//1 = = Array (' id ' = = 1, ' value ' = ' 1-1 '), *//2 = = Array (' id ' = = 2, ' value ' =&G T ' 2-1 '), *//) * @endcode * * @param array $arr Data source * @param string $keyField Convert by what key value * @param string $valueField corresponding key Value * * @return array of HashMap style after array conversion  Tohashmap (,,==((  [[]] =[(  [[]] =  1, ' value ' = ' 1-1 ', ' parent ' = + 1), * Array (' id ' = + 2, ' value ' = ' 2-1 ', ' parent ' = 1), * Array (' ID ' =&G T 3, ' value ' = ' 3-1 ', ' parent ' = + 1), * Array (' id ' = + 4, ' value ' = ' 4-1 ', ' parent ' = 2), * Array (' ID ' =&gt ; 5, ' value ' = ' 5-1 ', ' parent ' = 2), * Array (' id ' = + 6, ' value ' = ' 6-1 ', ' parent ' = 3), *); * $values = Arrayhelper::groupby ($rows, ' parent '); * * Dump ($values); *//According to the output of the parent group is *//Array (*///1 = Array (*//Array (' id ' = = 1, ' value ' = ' 1-1 ', ' parent ' = 1), * Array (' id ' = = 2, ' value ' = ' 2-1 ', ' parent ' = 1), *//Array (' id ' = + 3, ' value ' = ' 3-1 ', ' Parent ' =&G T 1), *//), *//2 = Array (*//Array (' id ' = + 4, ' value ' = ' 4-1 ', ' parent ' = 2), *//Array (' id ' = = 5, ' Value ' = ' 5-1 ', ' Parent ' and ' 2 ', *//), *//3 = Array (*//Array (' id ' = + 6, ' value ' = ' 6-1 ', ' parent ') = 3), *//), *//) * @endcode * * @param array $arr Data source * @param string $Keyfield The result of grouping by the key name * * @return Array   GroupBy (,=(  =[[][] =  1, ' value ' = ' 1-1 ', ' parent ' = + 0), * Array (' id ' = + 2, ' value ' = ' 2-1 ', ' parent ' = 0), * Array (' ID ' =&G T 3, ' value ' = ' 3-1 ', ' parent ' = + 0), * * Array (' id ' = 7, ' value ' = ' 2-1-1 ', ' parent ' = 2), * Array (' ID ') + 8, ' value ' = ' 2-1-2 ', ' parent ' = 2), * Array (' id ' = + 9, ' value ' = ' 3-1-1 ', ' parent ' = 3), * array (' id ' = +, ' value ' = ' 3-1-1-1 ', ' parent ' = 9), *); * * $tree = Arrayhelper::tree ($rows, ' id ', ' parent ', ' nodes '); * * Dump ($tree); *//output: *//Array (*//Array (' id ' = 1, ..., ' nodes ' = = Array ()), *//Array (' id ' = = 2, ..., ' nodes ' = =) Array (*//Array (..., ' parent ' = = 2, ' nodes ' = = Array ()), *//Array (..., ' parent ' = 2, ' nodes ' = = Array ()), *//), *//Array (' id ' = 3, ..., ' nodes ' = = Array (*//Array (' id ' = = 9, ..., ' parent ' = 3, ' nodes ' = Array (*//Array (...), ' parent ' = 9, ' nodes ' = ' = ' Array (), *//), *//) * @endcode * * If you want to obtain a subtree of any node root, you canTo use $refs parameters: * @code php * $refs = null; * $tree = Arrayhelper::tree ($rows, ' id ', ' parent ', ' nodes ', $refs); *//Output ID 3 node and all child nodes * $id = 3; * Dump ($refs [$id]); * @endcode * * @param array $arr Data source * @param string $keyNodeId Node ID field name * @param string $keyParentId node parent ID field name * @param str ing $keyChildrens Save the field name of the child node * @param boolean $refs whether to include the node reference in the returned result * * Return array of the array tree structure  Totree (,,= ' parent_id ',= ' Childrens ', &==(  =[][] =[[]] =&[=(  ==[((!([[] =&[=&[[[] =&[[] =&[   Treetoarray (,= ' Childrens '=(([]) &&([([] =(, Self::treetoarray (,([[] =[] = 1, ' value ' = ' 1-1 ', ' parent ' = + 1), * Array (' id ' = + 2, ' value ' = ' 2-1 ', ' parent ' = 1), * Array (' ID ' =&gt ; 3, ' value ' = ' 3-1 ', ' parent ' = + 1), * Array (' id ' = + 4, ' value ' = ' 4-1 ', ' parent ' = 2), * Array (' ID ' =&gt ; 5, ' value ' = ' 5-1 ', ' parent ' = 2), * Array (' id ' = + 6, ' value ' = ' 6-1 ', ' parent ' = 3), *); * * $rows = Arrayhelper::sortbycol ($rows, ' id ', SORT_DESC); * Dump ($rows); *//Output Result: *//Array (*//Array (' id ' = = 6, ' value ' = ' 6-1 ', ' parent ' = 3), *//Array (' id ' = 5, ' value ') = ' 5-1 ', ' parent ' = 2), *//Array (' id ' = + 4, ' value ' = ' 4-1 ', ' parent ' = 2), *//Array (' id ' = 3, ' Value ' = ' 3-1 ', ' parent ' = 1), *//Array (' id ' = = 2, ' value ' = ' 2-1 ', ' parent ' = 1), *//Array (' id ' = > 1, ' value ' = ' 1-1 ', ' parent ' = 1), *//) * @endcode * * @param array $array the array to sort * @param string $keyname Sorted key * @param int $dir Sort Direction * * @return Array sorted  Sortbycol (,,=Self::sortbymulticols (,(=SORT_ASC, * ' name ' = + sort_desc, *)); * @endcode * * @param array $rowset to sort by * @param array $args sorted by key * * @return array sorted  Sortbymulticols (,== ''(  =(  =[][] =[. = ' $sortArray [\ '.. '\'], ' .. ', '(() || (
                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                               < Span eval< span> (' Array_multisort ('. 
                                                                                                                                                                                                                                                                                                                               . ' $rowset); ' 
                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                    

http://www.bkjia.com/phpjc/440429.html www.bkjia.com true http://www.bkjia.com/phpjc/440429.html techarticle Cols (, = ([[] = [Tohashmap (,, = = [[]] = [[[]] = [[[]] = groupBy (, = (= [] = [[] = Totree (,, = ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.