Array_column PHP function Custom version php_version<5.5

Source: Internet
Author: User

<?phpif (!function_exists (' Array_columns ')) {/* * Array_column () for PHP 5.4 and lower versions            */function Array_columns ($input, $column _key, $index _key= ") {if (!is_array ($input)) return;            $results =array ();                if ($column _key===null) {if (!is_string ($index _key) &&!is_int ($index _key)) return false; foreach ($input as $_v) {if (array_key_exists ($index _key,$_v)) {$results [$_v[$i                    Ndex_key]]=$_v;            }} if (Empty ($results)) $results = $input;            }else if (!is_string ($column _key) &&!is_int ($column _key)) {return false;                }else{if (!is_string ($index _key) &&!is_int ($index _key)) return false; if ($index _key=== ") {foreach ($input as $_v) {if (Is_array ($_V) &&array_key _exists ($column _key,$_v)){$results []=$_v[$column _key]; }}}else{foreach ($input as $_v) {if (Is_array ($_v) &&array_key_exists ($column _key,$_v) &&array_key_exists ($index _key,$_v)) {$r                        esults[$_v[$index _key]]=$_v[$column _key];        }}}} return $results;    }} $testArray =array (Array (0=> ' Girl ', ' name ' = ' Judy '), Array (0=> ' boy ', ' name ' = ' Jerry ')    );    Echo ' <pre> ';    Print_r (Array_columns ($testArray, ' name '));    Print_r (Array_columns ($testArray, 0, ' name ')); Exit;? >

The custom Array_column function implements PHP version less than 5.5 can also be used

Array_column PHP function Custom version php_version<5.5

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.