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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.