Alternate array based on item value with PHP

142 views Asked by At

What's the best way to alternate array based on value. For example, I've an array pattern :

This array must respect this pattern base on 'category' : article / quote / video / article / video... Without article : quote / video / quote / video...

I would like to have this result :

[
    [
        'title' => 'Foo 1',
        'category' => 'article'
    ],
    [
        'title' => 'Foo 45',
        'category' => 'quote'
    ],
    [
        'title' => 'Foo 45',
        'category' => 'video'
    ],
    [
        'title' => 'Foo 2',
        'category' => 'article'
    ],
    [
        'title' => 'Foo 25',
        'category' => 'quote'
    ],
    [
        'title' => 'Foo 3',
        'category' => 'article'
    ]
];
0

There are 0 answers