Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:17:36+00:00 2026-06-02T23:17:36+00:00

Anyone can help me about multi dimensional arrays? I have an array that wanted

  • 0

Anyone can help me about multi dimensional arrays? I have an array that wanted to random arrays inside it, so therefore its hierarchy or there index value will be changed and different from the original arrangement of arrays, like:

This is the original arrays

Array(
    [0]=>Array(
             [title]       => 'Title 1'
             [description] => 'description here'
         )
    [1]=>Array(
             [title]       => 'Title 2'
             [description] => 'another description here'           
         )
    [2]=>Array(
             [title]       => 'Title Here Again'
             [description] => 'description here again'           
         )
)

That will be the original structure of the array above, and if you random it, let say this will be the outcome

This is the random-ed arrays

 Array(
        [0]=>Array(
                 [title]       => 'Title 2'
                 [description] => 'another description here'
             )
        [1]=>Array(
                 [title]       => 'Title 3'
                 [description] => 'another description again'           
             )
        [2]=>Array(
                 [title]       => 'Title 1'
                 [description] => 'description here'          
             )
    )

As you can see, values inside the arrays are being randomize at different positions, now the problem is i can’t get the exact logic on how to get the original array index like this -> ( [0] ) from randomized arrays. Like the value ‘Title 1’ its original index is [0], and after it was random-ed it became [2] but still i wanted ‘Title 1’ being assigned to index [0]. Here’s a short php code on how i randomized the arrays:

foreach (shuffleThis($rss->getItems()) as $item) {

    foreach($item as $key=>$value){
        if($key=='title'){
                $title=$value;
        }
        if($key=='description'){
            $description=$value;    
        }
    }
}
function shuffleThis($list) { 
  if (!is_array($list)) return $list; 

  $keys = array_keys($list); 
  shuffle($keys); 
  $random = array(); 
  foreach ($keys as $key) { 
    $random[] = $list[$key]; 
  }
  return $random; 
}

Just wanted to get they keys original array index from being random-ed.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:17:37+00:00Added an answer on June 2, 2026 at 11:17 pm

    If I understand you correctly, you want to change the order of the elements but preserve the keys. You can do that with a small modification:

    function shuffleThis($list) { 
        if (!is_array($list)) return $list; 
    
        $keys = array_keys($list); 
        shuffle($keys); 
        $random = array(); 
        foreach ($keys as $key) { 
            $random[$key] = $list[$key]; // CHANGE HERE that preserves the keys
        }
        return $random; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me with a question about webservices and scalability? I have written
I am new in Symbian UIQ. So anyone can help me out about following
My head is about to explode with this logic, can anyone help? Class A
I wonder if anyone can help - I have this error showing recently when
Does anyone can help about to serialize my tastypie api to response with plist
While reading about wireless technology, I usually meet the term provisioning. Anyone can help
if anyone can help me with this one... I have a string named text.
Can anyone help with converting data from an XML document into an associative array?
Can anyone help me about AChartEngine. Here the first thing I need is not
I wonder if anyone can help with the following. I have integrated both iAds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.