0

I want to know what other options are there other than foreach, to create the output array i want.

Input array is:

$arr = array(
    '4X2' => 86,
    '4X3' => 9,
    '4X4' => 5,
    '6X2' => 14,
    '6X4' => 1
);

Output array that i want to achieve is

Array
(
    [4x2] => Array
        (
            [title] => 4X2
            [search] => &vconfiguration[]=4X2
            [count] => 86
        )

    [4x3] => Array
        (
            [title] => 4X3
            [search] => &vconfiguration[]=4X2
            [count] => 9
        )

    [4x4] => Array
        (
            [title] => 4X4
            [search] => &vconfiguration[]=4X4
            [count] => 5
        )

    [6x2] => Array
        (
            [title] => 6X2
            [search] => &vconfiguration[]=6X2
            [count] => 14
        )

    [6x4] => Array
        (
            [title] => 6X4
            [search] => &vconfiguration[]=6X4
            [count] => 1
        )    
)

I've used array_walk to achieve the output but in it i'm using the array pass by reference which i don't want to do. This is my solution to do this but i want to avoid pass by reference (&$result).

$result = array();
array_walk($filterFacet, function($v, $k) use (&$result) {
  $result[$k] = array(  
      'title' => $k,  
      'search' => '&vconfiguration[]=' . $k,  
      'count' => $v  
      );
});

Any suggestions would be greatly appreciated.

yo black
  • 127
  • 1
  • 5

0 Answers0