Re: advice on how to build this array from an array.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,

thanks for your reply.

i have figured out, well kind of, and got the data i need but the problem is its nested within to many arrays!

Array ( 
	[threads & form types] => 
		Array ( [0] => Array ( [name] => imperial thread form [id] => 28 [page_cat_id] => 9 [main_nav] => true ) [1] => Array ( [name] => metric iso threads [id] => 29 [page_cat_id] => 9 [main_nav] => true ) ) 
	[material range] => 
		Array ( [0] => Array ( [name] => super duplex stainless steels [id] => 30 [page_cat_id] => 10 [main_nav] => true ) [1] => Array ( [name] => standard stainless steels [id] => 31 [page_cat_id] => 10 [main_nav] => true ) [2] => Array ( [name] => non ferrous [id] => 32 [page_cat_id] => 10 [main_nav] => true ) [3] => Array ( 	[name] => carbon based steels [id] => 33 [page_cat_id] => 10 [main_nav] => true ) ) 
) 

how can i get this just do its a $k => $v pair,

the key as it is [threads & form types] && [material range], and the value, the single array [Array ( [name] => imperial thread form [id] => 28 [page_cat_id] => 9 [main_nav] => true ) [1] => Array ( [name] => metric iso threads [id] => 29 [page_cat_id] => 9 [main_nav] => true )] ?

hope this makes sense

Adam


On 7 Jun 2011, at 22:25, Jasper Mulder wrote:

> 
> ----------------------------------------
>> From: ad84@xxxxxxxxxxxxxxxx
>> Date: Tue, 7 Jun 2011 21:50:27 +0100
>> To: php-general@xxxxxxxxxxxxx
>> Subject:  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
> 		 	   		  
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux