Jump to content

Recommended Posts

Suppose I have this array

1,A

2,B

3,C

4,D

5,E

 

How to random the array but only the numeric index (1 to 5)

 

Did you mean that you have an array like the following (regardless of how the code is written)

<?php
$arr = array(
1 => "A",
2 => "B",
3 => "C",
4 => "D",
5 => "E"
);

There is the shuffle function, you didn't exactly give many details so I'm not sure if that's appropriate.

 

I'm sorry it's my mistake,

I have this script to get 3 unique random data out of 10

 

$array = range(0, 10);

$keys = array_rand($array, 3);

echo $array[$keys[0]]; echo "<br />";

echo $array[$keys[1]]; echo "<br />";

echo $array[$keys[2]]; echo "<br />";

 

and now I want to use 2 dimensions array

 

$data=array(

0=>array("1","A"),

1=>array("2","B"),

2=>array("3","C"),

3=>array("4","D"),

4=>array("5","E")

)

 

how to get 2 unique random data from it?

 

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.