Reputation: 2279
I have this array:
Array ( [0] => Post Slider [1] => Post Slider Wide [2] => Post Slider )
And this second array:
Array ( [0] => Tools Sliders [1] => Tools Sliders [2] => modules-test )
When I use the PHP function array_combine, it does not include the duplicates, like this:
Array ( [Post Slider] => modules-test [Post Slider Wide] => Tool Sliders )
I'm confused how to get a desired result like this (without stripping the duplicates, complete one to one relationship):
Array ( [Post Slider] => Tools Sliders [Post Slider Wide] => Tools Sliders [Post Slider] => modules-test)
I would appreciate any help and tips..
Regards, Codex
Upvotes: 0
Views: 757
Reputation: 3823
$count1 = count($array1);
$count2 = count($array2);
$array = array();
if($count1==$count2){
foreach($array1 as $i=>$val){
$array[]=array($val,$array2[$i]);
}
}
You will get:
Array (
[0] => Array(
[0] => Post Slider
[1] => Tools Sliders
)
............
)
Upvotes: 0
Reputation: 152266
You will never have duplicated keys in your output array no matter what you will do. Keys are always unique.
The only solution is to assign to the key an array with, for example, two values.
$keys = array ( 'Post Slider', 'Post Slider Wide', 'Post Slider' );
$values = array ( 'Tools Sliders', 'Tools Sliders', 'modules-test' );
$output = array();
$size = sizeof($keys);
for ( $i = 0; $i < $size; $i++ ) {
if ( !isset($output[$keys[$i]]) ) {
$output[$keys[$i]] = array();
}
$output[$keys[$i]][] = $values[$i];
}
Upvotes: 1