I walk around here with some hesitation, I have passed an array with sub elements (so to speak) and I need three random values but these are obtained without repeating.
The array is as follows:
Array ( [0] => Array ( [uid] => 1 [ticket_code] => 0oreb8yo ) [1] => Array ( [uid] => 1 [ticket_code] => 2oeii8hm ) [2] => Array ( [uid] => 1 [ticket_code] => m0dwtjiw ) [3] => Array ( [uid] => 1 [ticket_code] => q6c7cymb ) [4] => Array ( [uid] => 1 [ticket_code] => zyqhm5bj ) [5] => Array ( [uid] => 1 [ticket_code] => amdqzjpi ) [6] => Array ( [uid] => 2 [ticket_code] => tzql7l42 ) [7] => Array ( [uid] => 2 [ticket_code] => gap0r6vf ) [8] => Array ( [uid] => 2 [ticket_code] => ypqum5yz ) [9] => Array ( [uid] => 4 [ticket_code] => smupluac ) [10] => Array ( [uid] => 4 [ticket_code] => 9d8jsha7 ) [11] => Array ( [uid] => 5 [ticket_code] => 6hdnja42 ) )
And I need you to get 3 "ticket_code" but no right to repeat the "uid".
I've been on trying as follows, but also repeats the "uid".
$ticketsWinners = array();
for ($i=0; $i < 3; $i++) {
$aux = array_rand($allTickets);
$aux2 = $allTickets[$aux]['uid'];
$ticketsWinners[] = array(
'uid' => $aux2,
'ticket_code' => $allTickets[$aux]['ticket_code']
);
}
Any way to do it without repeats?
We thank you in advance if anyone knows of something ^^