0

I'm trying to compare two arrays and use the difference of them to remove data from another array but as I use the resulting array to do a array_diff_key using an array_flip it returns; array_diff_key(): Expected parameter 1 to be an array, object given

$unchecked_cols = array_diff($selected_table_cols,$selected_cols);
        $tem_array = [];                    
        foreach ($selected_table_data as $key => $value) {
            $value =array_diff_key($value, array_flip($unchecked_cols));
            $tem_array[$key] = $value;
        }

this is the code and I've tried converting the 'unchecked cols' to an array using toArray method but then i get: Call to a member function toArray() on array error. what should i do in a case like this.

1 Answer 1

2

To convert object to array you can add (array) before your object

$unchecked_cols = array_diff($selected_table_cols,$selected_cols);
$tem_array = [];                    
foreach ($selected_table_data as $key => $value) {
     $value =array_diff_key((array)$value, array_flip($unchecked_cols));
     $tem_array[$key] = $value;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!!! it worked.... I tried many other things but i didn't think of that..
Glad to hear that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.