Hi. I'm trying to extract a range of indexes from an array in a specific manner.
If my array is:
$articleList = array (
array('article_id' => '1',
'category_id' => '1',
'article_text' => 'arbitary text'),
array('article_id' => '2',
'category_id' => '1',
'article_text' => 'arbitary text'),
array('article_id' => '3',
'category_id' => '2',
'article_text' => 'arbitary text'),
array('article_id' => '4',
'category_id' => '2',
'article_text' => 'arbitary text'),
array('article_id' => '5',
'category_id' => '2',
'article_text' => 'arbitary text'),
array('article_id' => '6',
'category_id' => '3',
'article_text' => 'arbitary text'),
array('article_id' =>' 7',
'category_id' => '3',
'article_text' => 'arbitary text'),
array('article_id' => '8',
'category_id' => '4',
'article_text' => 'arbitary text')
);
The first value is a primary key for the article, the second value is the primary key of the category the article belongs to. I want to extract the articles into a new array for each category, meaning a new array would be created to hold only articles from category 1, a new array with only category 2 articles, etc, etc.
Constraint: The number of articles per category varies.
Can anyone think of a way to achieve this? Is there a built-in PHP function that does it? I'd rather use a built-in function because of its speed.
Any help is very much appreciated, thank you.