2
Guys, I have this code here:
<?php
// Define um array com alguns sites:
$site[] = 'google.com';
$site[] = 'facebook.com';
// Escolhe um valor aleatório (respeitando o total de sites)
$destino = rand(0, (count($site) - 1));
// Redireciona o usuario:
header("Location: " . $site[$destino]);
?>
He currently randomly chooses between the two links and opens one of them. But I wanted a simple change, and I don’t know how to do it exactly because I don’t understand much of it. I wanted the second option to have two options. But what do you mean? I wanted something like this?
<?php
// Define um array com alguns sites:
$site[] = 'google.com';
$site[] = 'youtube.com' ouuu 'facebook.com';
// Escolhe um valor aleatório (respeitando o total de sites)
$destino = rand(0, (count($site) - 1));
// Redireciona o usuario:
header("Location: " . $site[$destino]);
?>
So, an Andom inside an Andom. Someone could help me with this?
And why the
facebook.com
could not enter as a third item in the array?– Woss
Because I wanted only about 25% of the hits to this site. Google would be the main redirect, in case about 50% chance. And then this other 50% I wanted to divide between the other two links, so I can’t create a third array, if it wouldn’t be about 33% chance of access in each array
– RafaelMacedo
So the question should be this xD "How do you draw a value considering different weights for each value" or something like that.
– Woss
Simply add another google entry or make an array that puts the weight of each element and see which index was based on the Rand range (:
– Felipe Avelar