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 )