Foreach multiple arrays into one

Can’t seem to figure out how to do it.

I have 5 arrays with similar structure:

    [13440] => 44 años
    [13477] => 39 años

All arrays have same key but different values!

Out of those 5 I need to create one:

$AjaxData[] = array(
"ProfileUrl"=> "",  

Please teach me how it is done.

I assume it’s got to be foreach inside foreach.

i don’t see any relation between these two sets of data.

Please read my post. I have 5 similar arrays and I need to foreach them into one. All arrays have same key which corresponds to userId.

i don’t see what that would have to do with your example in $AjaxData and how any of the first data would covert to this.

$AjaxData = array();

so that’s your solution?

I think that I understand what you want.

I assume that you have 5 arrays with the same key, but different names.

So your array wouldn’t be

[13440]=>44 years;

I assume that your array would be something like

arrayName[13440]=>44 years;

It has been a long time since I’ve done this and I forgotten quite a bit of my javascript. But I believe that the answer you’re looking for would go something like this or close to this

$AjaxData[] = array(
"ProfileUrl"=>arrayName3[13440] ,  

If it is the very first property of each array what you want, I think this might work.

Take it with a pintch of salt though. It’s been a few years since I used JavaScript. If this doesn’t work, I will need to refresh my knowledge of associative arrays :smiley:

Could you possibly show an example of how you expect the finished array to look, with some sample data? Say, two of the original arrays, and how those two would look in the combined array.

I agree that a more complete question will help to find the right answer

The PHP manual has a couple of functions which may be useful, complete with examples:

There are also some functions dealing with Json errors.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.