Skip to content
Advertisement

add field and value to array while looping through?

I have the folowing 2 arrays, and I need to add the value of the first one depending on the ID value of the second one as Key so I can order the 2nd array DESC:

$views:

JavaScript

And I have the folowing array object:

$most_seen_list :

JavaScript

with the next foreach Im going through it and I want to change the [0]..[1]..[3] key with the value I get from another array:

JavaScript

Expected output:

JavaScript

Advertisement

Answer

I assume you already sorted the $views array. So you will need to process each of the array of $most_seen_list objects to find the right one using an inner loop

JavaScript

RESULTS

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement