PHP built-in function Analysis Array_column ()

Source: Internet
Author: User

1 php_function (array_column)2 {3Zval *zcolumn = null, *zkey = NULL, *data;4HashTable *Arr_hash;5Zval *zcolval = NULL, *zkeyval =NULL, RVC, RVK;6 7     //If you receive a null variable in a PHP language, it will be converted directly to NULL in the C language, rather than encapsulated as a is_null type Zval8     if(Zend_parse_parameters (Zend_num_args (),"hz!| z!", &arr_hash, &zcolumn, &zkey) = =FAILURE) {9         return;Ten     } One  A     /*checks whether COLUNM and index are valid (numbers and objects only, and objects need to be converted to strings).  - * Invalid quote the%s key should is either a string or an integer warning error.  -     */ the     if(Zcolumn &&!array_column_param_helper (Zcolumn,"column")) || -(Zkey &&!array_column_param_helper (Zkey,"Index"))) { - Return_false; -     } +     //Initialize return value - Array_init (return_value); +     //Iterating through an array A Zend_hash_foreach_val (Arr_hash, data) { at zval_deref (data); -  -         if(!zcolumn) {//Column Not set -Zcolval =data; -}Else if((Zcolval = Array_column_fetch_prop (data, zcolumn, &rvc) = = NULL) {//The value of the column is null, skip, and go to the next loop -             Continue; in         } -  to         /*Failure would leave zkeyval alone which would land us on the final else block below + * Which is to append the value as Next_index -          */ the         if(zkey) { *Zkeyval = Array_column_fetch_prop (data, Zkey, &RVK);//gets the column corresponding to the Zkey as the key/index of the returned array $         }Panax Notoginseng  - z_try_addref_p (zcolval); the         //array of Return values: Array (zkeyval=>zcolval,...) +         if(Zkeyval && z_type_p (zkeyval) = =is_string) { A zend_symtable_update (z_arrval_p (Return_value), z_str_p (Zkeyval), zcolval); the}Else if(Zkeyval && z_type_p (zkeyval) = =Is_long) { + Add_index_zval (Return_value, Z_lval_p (zkeyval), zcolval); -}Else if(Zkeyval && z_type_p (zkeyval) = =is_object) { $Zend_string *key =zval_get_string (zkeyval); $ zend_symtable_update (z_arrval_p (return_value), key, zcolval); - zend_string_release (key); -}Else { the             //If there is no zkeyval, the return value array is an indexed array - Add_next_index_zval (Return_value, zcolval);Wuyi         } the         /*Clean up memory*/ -         if(Zcolval = = &RVC) { WuZval_ptr_dtor (&RVC); -         } About         if(Zkeyval = = &RVK) { $Zval_ptr_dtor (&rvk); -         } - } zend_hash_foreach_end (); -}

PHP built-in function Analysis Array_column ()

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.