The function for deleting an element value in an array on the Internet cannot be understood. Can anyone help me?

Source: Internet
Author: User
The function for deleting an element value in an array on the Internet cannot be understood. Can anyone help me? Array functions

The following is a function used to delete the value of an element in an array:
Function array_remove_key ($ array, $ keys) {$ num = count ($ keys); $ num_last = $ num-1; $ this_array_0 = & $ array; $ last_key = $ keys [$ num_last]; for ($ I = 0; $ I <$ num_last; $ I ++) {$ this_key = $ keys [$ I]; $ this_var_name = 'This _ array _'. $ I; $ next_var_name = 'This _ array _'. ($ I + 1); if (! Array_key_exists ($ this_key, $ this_var_name) // here, when the second loop is performed, $ this_var_name is a string {break ;} $ next_var_name = & $ {$ this_var_name} [$ this_key];} unset ($ {$ next_var_name} [$ last_key]); return $ array ;}


In the first loop, $ next_var_name = & $ {$ this_var_name} [$ this_key]; has assigned $ this_array_1 to an element in the array, when we judge array_key_exists ($ this_key, $ this_var_name) in the second loop, $ this_var_name is $ this_array_1, which is not an array, but a value, I also tried to report an error.

I am not familiar with the overall idea of this function. could you please tell me? thank you!


Reply to discussion (solution)

This code is really bad, and there is no test code, no mood analysis
This function is used to delete all elements in $ keys in the $ array key.
Just like this

$a = array(1,2,3,4,5);$b = array(2,4);print_r(array_diff_key($a, array_flip($b)));//Array ( [0] => 1 [1] => 2 [3] => 4 )

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.