php - Sorting and outputting a multi-dimensional array -


I have a multi-dimensional array that looks like this:

  function art_appreciation_feeds ( ) ($ 'Item' = (array ('site' => gt; '' 'uri' =>, 'feed' =>), array ('site' = & gt; '', 'URI = & gt;', 'feed' = & gt; ''), array ('site' => gt; '', 'uri' = & gt; '', 'feed' = & Gt; ''), array ('site' => gt; '', 'uri' = & gt; '', 'feed' =>);), return $ item;}  

OK, so I use the function to exclude array values:

  foreach ($ i => item as $ line) { 

What do I do I'm going to, which adds another value for that array named category so that I have:

  array (array ('site' = & gt; ; '', 'Uri' = & gt; '', 'feed' => gt; 'class' =>, ''),);  

and when I am going through the loop above, then it will be with category field with the and lt; h2 & gt; range & lt; / H2> at the top of each section.

Is that the best way to do this, and if so, how can I change my loop to adjust it? Warning: If you think better, then I can change the array.

Thank you!

I'm sure there are better ways to go about it and not sure that it's your position Easy to do in, but just a suggestion. Why is the category not in the form of an array key and for putting all records related to that category as sub-record?

For example:

  $ items ['catname1'] [] = array ('site' => gt; '', 'uri' = & gt; '', 'Feed' = & gt; ''); $ Items ['catname2'] [] = array ('site' => gt; '', 'uri' = & gt; '', 'feed' =>); $ Items ['catname1'] [] = array ('site' => gt; '', 'uri' = & gt; '', 'feed' =>);  

And then sorting by the array key?

Or if you do not want to add that extra layer, add a counter value to the queue name and store its own name in the alias

  $ items ['catname1 '. $ C] = array ('site' = & gt; '', 'uri' = ';' ',' feed '=>;'; cat => 'catname1'); $ Items ['catname2'. $ C] = array ('site' => gt; '', 'uri' = & gt; '', 'feed' => gt; cat => 'catname2'); $ Items ['catname1' $ C] = array ('site' => gt; '', 'uri' =>; '' 'feed' = 'gt;' ', cat =>' catname1 '); You should be able to sort the array keys easily by using   

ksort () .


Comments