Skip to content
Advertisement

Tag: arrays

Merge array by element’s parent_id in PHP

I am not sure if this has already been asked in PHP but I couldn’t find the answer I have an array that lists id and parent id I want to loop by parent id backwards to merge the grandchildren into the children and the children into the parent. I tried to find the parent by id using array search

array_push() expects parameter 1 to be array, int given

I am getting array_push() expect parameter one to be an array, any solution? Answer you have referenced the variable as an array first time. but when you are using it for array push with $activeCourses = it becomes an integer field as array_push returns an integer value and then when it comes to next array push in the next iteration,

converting an object to an array in laravel

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 this is the code and I’ve tried converting the ‘unchecked cols’ to an array using toArray

Advertisement