1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Array

Discussion in 'Development' started by esh123cookie, Jul 18, 2020.

  1. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    If I do

    $array = array("test1", "test2", "test3");
    array_rand($array, 2);

    How would I get the result of this so I could store it as data?
     
  2. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Check it by yourself on phptester.net
    PHP:
    $array = ["hi""ho""xd""bro"];
    $randomKeys array_rand($array2);
    $randomArray = [$array[$randomKeys[0]], $array[$randomKeys[1]]];

    print_r($randomArray);
     
  3. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    Ye thank you
     
    Diduhless likes this.
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    $array = ["a""b""c""d""e"];

    $randomValue $array[array_rand($array1)];
    var_dump($randomValue); // random output string(1) "c"

    $randomizedArray $array;
    shuffle($randomizedArray);
    var_dump($randomizedArray); // random output array(5) { [0]=> string(1) "b" [1]=> string(1) "c" [2]=> string(1) "e" [3]=> string(1) "a" [4]=> string(1) "d" }

    $twoRandomValues array_slice($randomizedArray02);
    var_dump($twoRandomValues); // random output array(2) { [0]=> string(1) "e" [1]=> string(1) "a" }

     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.