samedi 6 janvier 2018

Undefined offset while randomising a variable?

$units = array(
    "R" =>"Kid Pan", "PO Krillen", "Android #16", "Android #19",
    'SR'=>'Vegeta', 'Piccolo', 'Botamo', 'SSJ2GokuGT', 'CaptainGinyu',
    'SSR'=>'TEQPerfectCell', 'STRGogeta', 'PHYKidBuu', 'STRBroly',
);
    echo $units[rand(0, count($units) - 1)] . "\n";

This code works fine, but sometimes there are errors, some with differnet numbers? For example; "NOTICE Undefined offset: 10 on line number 8" and NOTICE Undefined offset: 12 on line number 8

By the way, I'm testing this code with http://phptester.net/

(I'm a noob - sorry :/)




Aucun commentaire:

Enregistrer un commentaire