How to randomize an array json in php
JSON PART:
file.json
[ { "Country":"Germany", "male":["Andrew","Michael","John"], "female":["Emily","Hannah", "Mia"], "id":["1","2","3"] } ]
PHP PART:
$f = file_get_contents("file.json");
$file = json_decode($f, true);
$gm = $file["male"];
$male = $gm[rand(0, count($gm) - 1)];
$gf = $file["female"];
$female = $gf[rand(0, count($gf) - 1)];
echo 'male'. $gm. 'female'. $gf;
i don't know the problem :(
Aucun commentaire:
Enregistrer un commentaire