MemoryRefresh!

Array / Randomize   Randomize



Questions 1 Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


shuffle()
<?php $cards = array (1, 2, 3, 4); shuffle ($cards); var_dump ($cards); // [3, 4, 1, 2] randomly shuffleAssoc()
<?php function shuffleAssoc(&$arr) { $keys = array_keys($arr); shuffle($keys); $new = array(); foreach($keys as $v) $new[$v] = $arr[$v]; $arr = $new; return true; } $arr = array("a" => "aa", "b" => "bb", "c" => "cc"); shuffleAssoc($arr); var_dump($arr); array_rand() - extract at random
<?php $cards = array (1, 2, 3, 4); $keys = array_rand($cards, 2); print_r($keys); // [0, 3] randomly php.net stackoverflow.com

Related Pages

Basics
Operations
Create
Key-value
Search
Modify
Pointer
Sort
Stacks
Randomize
Storage


0% 100%
 
 
0 pages 91 pages
1) Randomize the order of an array








shuffle()
<?php $cards = array (1, 2, 3, 4); shuffle ($cards); var_dump ($cards); // [3, 4, 1, 2] randomly shuffleAssoc()
<?php function shuffleAssoc(&$arr) { $keys = array_keys($arr); shuffle($keys); $new = array(); foreach($keys as $v) $new[$v] = $arr[$v]; $arr = $new; return true; } $arr = array("a" => "aa", "b" => "bb", "c" => "cc"); shuffleAssoc($arr); var_dump($arr); array_rand() - extract at random
<?php $cards = array (1, 2, 3, 4); $keys = array_rand($cards, 2); print_r($keys); // [0, 3] randomly php.net stackoverflow.com

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References