MemoryRefresh!

Randomize



Questions 1 Answers 0%

Pages   0 from 51
Questions   0 from 84

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
http://php.net
https://stackoverflow.com
Questions

Related pages

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


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





Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


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
http://php.net
https://stackoverflow.com



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com