3v4l.org

run code in 300+ PHP versions simultaneously
<?php $adjectives = [ "Abaft", "Abandoned", "Abased", "Abashed", "Abasic", "Abbatial", "Abdicable", "Abdicant", "Abdicative", "Abdominal", "Abdominous", "Abducent", "Aberrant", "Aberrational", ]; $animals = [ "aardvark", "aardwolf", "abalone", "abyssiniancat", "abyssiniangroundhornbill", "acaciarat", "achillestang", "acornbarnacle", "acornweevil", "acornwoodpecker", "acouchi", "adamsstaghornedbeetle", "addax", "adder", ]; class AnimalIDs{ protected $adjectives = null; protected $animals = null; public function __construct($adjectives, $animals){ $this->adjectives = $adjectives; $this->animals = $animals; } public function get($adjectivesNum = 1,$format = 'dash'){ $result = ''; $delim = ''; for($n = 0; $n < $adjectivesNum; $n++){ if($format === 'dash'){ $result .= $delim . $this->adjectives[rand(0,count($this->adjectives) - 1)]; $delim = '-'; } } $result .= $delim . $this->animals[rand(0,count($this->animals) - 1)]; return $result; } } $a = new AnimalIDs($adjectives, $animals); echo $a->get()."\n"; echo $a->get(2)."\n";

preferences:
27.36 ms | 402 KiB | 5 Q