Unstoppable Domains โ€” Expired Auctions

How would I...

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Barrucadu

Established Member
Impact
64
Get 5 random values from an array?
And display them in alphabetical order.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
PHP:
asort(array_rand($myarray, 5)); // for sorting values
ksort(array_rand($myarray, 5)); // for sorting keys

You can use sort() but it rewrites the keys
 
Last edited:
0
•••
PHP:
asort(array_rand($videos, 5));

just returns the first 5 videos (ie: not choosing 5 random ones)
 
0
•••
dunno, the function is array_rand, i use it quite alot.

try it without the sorts

PHP:
$arr = array('dog','cat','cow','horse','fish');
$rnd =(array_rand($arr,2));
echo $arr[$rnd[0]] . "<br/>";
echo $arr[$rnd[1]] . "<br/>";

then try this
PHP:
$arr = array('dog','cat','cow','horse','fish');
$rnd =(array_rand($arr,2));
foreach($rnd as $a){
	$temp[] = $arr[$a];
}
asort($temp);
print_r($temp);
 
Last edited:
0
•••
Thanks, working now
 
0
•••
Appraise.net
Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back