Jump to content

how to get random value from array 2 dimentions


sacox

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?

 

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.