Generate arrays from one array in PHP

I have one array with 4 elements $array1 = array('A', 'B', 'C', 'D');
How can I grenerate 3 arrays like:

$arr1 = array(
    'A'=>'B', 
    'C'=>'D'
);

$arr2 = array(
    'A'=>'C', 
    'D'=>'B'
);

$arr3 = array(
    'A'=>'D', 
    'C'=>'B'
);

My problem is:
I have an array with n elements (n%2 == 0 and n>=4). I want to generate n-1 arrays from given array, every array has n/2 elements. Every element has a pair of key and value like above. (note that: A, B, C, D appear only once in an array). Please, help me!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s