mercredi 19 avril 2017

Simple random variabel php whit out repeate

I stand with that a simple problem that I want to make the same code just where it is not possible for it to print two identical variables like:

2.php 2.php 3.php

it should only mix them instead as the 3 files change location every time but does not repeat itself.

a correct answer is:

4.php 2.php 3.php

and

3.php 4.php 2.php

hope you understand the code looks like this:

<?php


$first = '2.php';
$second = '3.php';
$third = '4.php';

    $array = array($first, $second, $third);
    for ($i=0; $i<3; $i++) {
    echo $array[rand(0, count($array) - 1)] . "\n";
    }

Aucun commentaire:

Enregistrer un commentaire