contao/import — Issue #3253: Issue in DataContainer::combiner() since Rev.641
Author: aschempp
Created: 2011-11-29 21:11:42+00:00
State: open
Labels: backend, Defect

In Revision 641 (branches/contao-2.10), you changed the `combiner()` function to use reverse sorting. However, this will result in non-working palette names when having an even number of selectors. Unfortunately, there is no description or reference to a ticket why you changed that. Here is an example (from Isotope eCommerce):

```
'__selector__' => array('type', 'variant_option'),
```

Old result:

```
Array
(
[0] =>
[1] => variant_option
[2] => imageselectvariant_option
[3] => imageselect
)
```

New result:

```
Array
(
[0] => imageselect
[1] => imageselectvariant_option
[2] => variant_option
)
```

As you can see, the new result will match `imageselect` (field "type") before matching `imageselectvariant_option` (type + checkbox name).

I googled for another approach to combining, and found the following site: http://docstore.mik.ua/orelly/webprog/pcook/ch04_25.htm
Using the example as guidance, I came up with this:

```
protected function combiner($names)
{
// initialize by adding the empty set
$return = array(array());

foreach ($names as $element)
{
foreach ($return as $combination)
{
array_push($return, array_merge($combination, array($element)));
}
}

$return = array_reverse($return);
$return = array_map('implode', $return);

return array_filter($return);
}
```

The function will return:

```
Array
(
[0] => imageselectvariant_option
[1] => variant_option
[2] => imageselect
)
```

Regarding Ticket #189, according to the mentioned site (and my knowledge), PHP keeps an internal copy of an array when using foreach, therefore altering the array will not affect foreach.

Related issues: #189

--- _Originally created on July 11th, 2011, at 03:11pm (ID 3253)_