Advertisement
HristoBaychev

belot1

Mar 28th, 2023
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2.  
  3. $number = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];
  4. $shape = ["hearts", "diamonds", "clubs", "spades"];
  5.  
  6. $allCards = [];
  7.  
  8. foreach ($shape as $shapes) {
  9.     foreach ($number as $numbers) {
  10.         if ($numbers == '2' || $numbers == '3' || $numbers == '4' || $numbers == '5' || $numbers == '6'){
  11.             continue;
  12.         }
  13.         $card = $numbers . ' ' . $shapes;
  14.         array_push($allCards, $card);
  15.     }
  16. }
  17.  
  18. echo "All cards before: ==> 32 ".PHP_EOL;
  19. print_r($allCards);
  20.  
  21. $players = [
  22.     [],
  23.     [],
  24.     [],
  25.     []
  26. ];
  27.  
  28.  
  29.  
  30. for ($i = 0; $i < 3; $i++){
  31.     for ($j = 0; $j < 4; $j++){
  32.         array_push($players[$j], array_pop($allCards));
  33.     }
  34. }
  35.  
  36. for ($i = 0; $i < 2; $i++){
  37.     for ($j = 0; $j < 4; $j++){
  38.         array_push($players[$j], array_pop($allCards));
  39.     }
  40. }
  41.  
  42. for ($i = 0; $i < 3; $i++){
  43.     for ($j = 0; $j < 4; $j++){
  44.         array_push($players[$j], array_pop($allCards));
  45.     }
  46. }
  47.  
  48.  
  49. echo "All cards after: ==> 0 ".PHP_EOL;
  50. print_r($allCards);
  51. echo "Player cards: ==> ".PHP_EOL;
  52. print_r($players);
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement