Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $number = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];
- $shape = ["hearts", "diamonds", "clubs", "spades"];
- $allCards = [];
- foreach ($shape as $shapes) {
- foreach ($number as $numbers) {
- $card = $numbers . ' ' . $shapes;
- array_push($allCards, $card);
- }
- }
- echo "All cards before: ==> 52 " . PHP_EOL;
- print_r($allCards);
- $cardForBelot = [];
- foreach ($allCards as $card) {
- $card_parts = explode(" ", $card);
- $number = $card_parts[0];
- if ($number == '2' || $number == '3' || $number == '4' || $number == '5' || $number == '6'){
- continue;
- }
- array_push($cardForBelot, $card);
- }
- echo "All cards after ==> 32" . PHP_EOL;
- print_r($cardForBelot);
- shuffle($cardForBelot);
- echo "Shuffle cards: ==>";
- print_r($cardForBelot);
- $players = [
- "Player One" => [],
- "Player Two" => [],
- "Player Three" => [],
- "Player Four" => []
- ];
- for ($i = 0; $i < 3; $i++) {
- foreach ($players as $name => $cardForRemove) {
- array_push($players[$name], array_pop($cardForBelot));
- }
- }
- for ($i = 0; $i < 2; $i++) {
- foreach ($players as $name => $cardForRemove) {
- array_push($players[$name], array_pop($cardForBelot));
- }
- }
- for ($i = 0; $i < 3; $i++) {
- foreach ($players as $name => $cardForRemove) {
- array_push($players[$name], array_pop($cardForBelot));
- }
- }
- echo "All cards after: ==> 0 " . PHP_EOL;
- print_r($cardForBelot);
- echo "Player cards: ==> " . PHP_EOL;
- foreach ($players as $nameOfPlayer => $cards) {
- echo $nameOfPlayer . " ==>> ";
- print_r($cards);
- echo PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement