Jump to content

Shuffle Multidimensional Array


President Obama

Recommended Posts

Ok I'm really lost here, what I need to do is shuffle a 2D array. Now when I shuffle them I want to keep both columns aligned to say. Like I only want the index to change.

 

Kinda like this:

 

Index        Id          URL

0                [2          www.e] I want the bracketed stuff to stay aligned.

1                [6          www.b]

2                [12        www.c]

3                [60        www.h]

 

But I want them in different positions on every page load. So when I echo array[1][0] it will always be different. Is this even possible?

 

 

Link to comment
https://forums.phpfreaks.com/topic/225388-shuffle-multidimensional-array/
Share on other sites

eh should of explained my self better. What I'm doing is pulling 4 ads at random out of the db, but with each pull I want to add 1 to the views for that specific ad.

 

As in the links I only want the URL but with the views I want the Id to compare to the database and find out which ad to add a view to. Also if I use rand 4 times it will pull duplicates which I also don't want. Hard to explain.

Ok I found a way to totally ditch my multidimensional array. What I did is make 2 arrays one with the id's and one with the links then I used array_combine to combine them to a new array which has the indexes as the id's, now I can use shuffle on it and add views.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.