Page 1 of 1

I want to combine two arrays.

Posted: Sat May 17, 2008 2:18 pm
by mboer
I have this code:

Code: Select all

 
    $cards = array ();
    $cards = array ('2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A');
    
    $suits = array ();
    $suits = array ('Spades', 'Clubs', 'Hearts', 'Diamonds');
What I'm aiming for is to combine the two arrays into a single new array with a result output in the line of:

$new_array = array ('2 Spades', '2 Clubs', '2 Hearts', '2 Diamonds', '3 Spades', '3 Clubs'); ... etc.

I hope you understand what I'm getting at, I only have limited PHP knowledge?

Re: I want to combine two arrays.

Posted: Sat May 17, 2008 3:20 pm
by Eran

Code: Select all

 
$cardSuites = array();
foreach($cards as $card) {
       foreach($suits as $suit){
              $cardSuites[] = $card . ' ' . $suit;
       }
}