RE: [PHP] advice on how to build this array from an array.
| From: | Jasper Mulder | Date: | Tue, 07 Jun 2011 21:25:43 +0000 |
| Subject: | RE: [PHP] advice on how to build this array from an array. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313451@lists.php.net to get a copy of this message | ||
----------------------------------------
> From: ad84@blueyonder.co.uk
> Date: Tue, 7 Jun 2011 21:50:27 +0100
> To: php-general@lists.php.net
> Subject: [PHP] advice on how to build this array from an array.
>
> hi all,
>
> please forgive me if i do not make sense, ill try my best to explain.
>
>
> i have this array or arrays.
>
> Array ( [name] => super duplex stainless steels [id] => 30 [page_cat_id] => 10
> [main_nav] => true [cat_name] => material range )
> Array ( [name] => standard stainless steels [id] => 31 [page_cat_id] => 10 [main_nav]
> => true [cat_name] => material range )
> Array ( [name] => non ferrous [id] => 32 [page_cat_id] => 10 [main_nav] => true
> [cat_name] => material range )
> Array ( [name] => carbon based steels [id] => 33 [page_cat_id] => 10 [main_nav] =>
> true [cat_name] => material range )
>
> is it possible to build an array and use the [cat_name] as the key and assign all the pages to
> that cat_name?
>
> what im trying to achieve is a category of pages but i want the cat_name as the key to all the
> pages associated to it
>
> hope i make sense
>
> kind regards
>
> Adam
Suppose that $arrays is your array of arrays.
Then is
$res = array();
foreach($arrays as $item){
$res[$item['cat_name']][] = $item;
}
what you are looking for?
Best regards,
Jasper Mulder