You are here: Re: array_multisort() problem « PHP Language « IT news, forums, messages
Re: array_multisort() problem

Posted by Laiverd.COM on 06/20/07 17:53

For future reference. This is the solution:

// sorting the array of pages
foreach($items_arr as $index => $arr){
foreach( $items_arr[$index]['pages'] as $pageindex => $page){
$page_order[$pageindex] = $page['page_order'];
}
//echo count($page_order); ---> turns out that $page_order length grows on
each iteration
array_multisort($page_order, SORT_ASC,SORT_NUMERIC,
$items_arr[$index]['pages']);
$page_order = NULL; // ---- > reset the $page_order array
}

Cheers,
John


"Laiverd.COM" <share_your_knowledge@someserver.nl> wrote in message
news:46783078$0$37725$5fc3050@dreader2.news.tiscali.nl...
>I have a threedimensional array in which I need to sort items in the first
>dimension and items in the second dimension. The last items need to be
>sorted according to a value of a key in the third dimension.
>
> De basic structure of one of the items is (the second element in this
> case):
> // this is the array $items_arr
> 1 = Array
> 1 > main_order = 2
> 1 > pages = Array
> 1 > pages > 0 = Array
> 1 > pages > 0 > page_order = 1
> 1 > pages > 1 = Array
> 1 > pages > 1 > page_order = 3
> 1 > pages > 2 = Array
> 1 > pages > 2 > page_order = 2
>
> So I need to sort firstly on 'main_order', and after that I need to sort
> the items within 'pages' according to 'page_order'. I've tried everything
> I can think of, but cannot get it to work properly. This is what I have
> now:
>
> // sorting the array by main item order --------------------> this works
> perfect
> foreach ($items_arr as $key => $row) {
> $main_order[$key] = $row['main_order'];
> }
> array_multisort($main_order, SORT_ASC,SORT_NUMERIC, $items_arr);
>
> // sorting the array of pages -----------------------------> this works
> but throws a Warning: array_multisort() [function.array-multisort]: Array
> sizes are inconsistent in ...
> foreach($items_arr as $index => $arr){
> foreach( $items_arr[$index]['pages'] as $pageindex => $page){
> $page_order[$pageindex] = $page['page_order'];
> }
> array_multisort($page_order, SORT_ASC,SORT_NUMERIC,
> $items_arr[$index]['pages']);
> }
>
> Anybody out there who can set me on the right track?
>
> Thanks in advance,
> John
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация