So I am Trying To Make A CrateKeys Plugin And When I Add The The $prize array it always outputs stone and one 1 stone idk here is the code PHP: public function crateKeys(PlayerInteractEvent $event) { $player = $event->getPlayer(); $block = $event->getBlock(); if($block->getId() == 54 && !$event->isCancelled()) { if($player->getInventory()->getItemInHand()->getId() == 341) { $prizes = array(10,10); $prize = array_rand($prizes); $player->getInventory()->addItem(item::get($prize)); $player->getInventory()->removeItem(item::get(341, 0, 1)); $event->setCancelled(true); } else { $player->sendMessage("You need a Crate Key to open a Crate!"); $event->setCancelled(true); } } elseif(!$event->isCancelled()) { $event->setCancelled(false); }} }
Not really, this way you can get random keys and then pull out the values. If it was setup the other way around, it would be very inefficient to get the keys of the values.
But it is less often that we use it like that. If we really need that, we could just like array_rand_value(array_keys($array)).