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 8216957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:18:48+00:00 2026-06-07T12:18:48+00:00

How can I randomize the results on this code ? I have an array

  • 0

How can I randomize the results on this code ?

I have an array with more than four items on it, but I will like to get four of them only but not in order, how do I suppose to do that ? It can be done using foreach(array_slice ??

$i = 0;
foreach(array_slice($items_array,0,4) as $item) {
$output .= 'Item ID:'.$item['id'];
$i++;
}

My array

a:6:{i:0;a:4:{s:5:"title";s:17:"Spedition";s:2:"id";s:11:"ZCXbgH1JDt4";s:3:"url";s:40:"embed/ZCXbgH1JDt4";s:5:"image";s:38:"transport";}i:1;a:4:{s:5:"title";s:77:"DC...... 
  • 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-07T12:18:49+00:00Added an answer on June 7, 2026 at 12:18 pm

    Solved

    $item = array_rand($items_array, 4); //get only four at random
    $i=0;
    while($i<=3) { // instead of 4 you set it at 3 because the counter starts at 0
    $output = 'Item ID:'.$items_array[$item[$i]]['id'];             
    $i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use randomize and rnd to get a repeating list of random
I can not figure out why the following AJAX code will only load the
how can i randomize for this variable one word? var = 'stack'; for (i=0;
I would like to know how I can randomize the order in which some
I have 62 base64 characters that I want to randomize. How can I do
I can sort a int* array using stl, plain and simple like std::sort(myarray, myarray
how can an array be created that randomizes results from 3 different values 0,1,2
Hi can anyone tell me how to make this javascript code show full screen
Anyone can help me about multi dimensional arrays? I have an array that wanted
I'm trying to create an array of strings that can be randomized and limited

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.