I've been playing around with array_unique and array_shift, but not sure exactly how to use it for this particular situation, or even if it's what I should use...

Suppose my array looks like this:

Array
(
    [0] => Array
        (
            [color] => orange
            [opts] => Array
                (
                    [title] => Dracula
                )

    )

[1] => Array
    (
        [color] => orange
        [opts] => Array
            (
                [title] => Moby Dick
            )

    )

[2] => Array
    (
        [color] => gray
        [opts] => Array
            (
                [title] => Who's On First
            )

    )

I'm trying to figure out a way to group the color, but still retain the different titles. So, I suppose what I'm hoping to end up with, is this:

Array 
(
            [orange] => Array ( [0] => Dracula [1] => Who's On First )
            [grey] => Array ( [0] => Moby Dick )
)

Is there a way to do that?

    You could loop through the first array and populate a 2nd array from it, something like (untested):

    $newArray = array();
    foreach ($arr1 as $data)
    {
       if (isset($data['color']))
       {
          if(!empty($data['opts']))
          {
             foreach ($data['opts'] as $key => $opt)
             {
                if ($key == 'title')
                {
                   $newArray[$data['color']][] = $opt;
                }
             }
          }
       }
    }
    
      Write a Reply...