I want to combine two arrays.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mboer
Forum Newbie
Posts: 2
Joined: Sat May 17, 2008 2:11 pm

I want to combine two arrays.

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: I want to combine two arrays.

Post by Eran »

Code: Select all

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