PDA

View Full Version : Sort foreach statement



robbiez
01-17-2012, 03:42 PM
Hi

I have a few lines of code that returns a number of items. I need to sort the order of these items in the numeric order of one of the array values.
This is the current code:

foreach ($_from as $this->_tpl_vars['k'] => $this->_tpl_vars['ARR_F']):
$this->_foreach['frchFrameList']['iteration']++;

and I want to sort the results by the value of
$this->_tpl_vars['ARR_F']['depth_mm']

I have tried using sort() but just get syntax errors.

Thanks in advance for any assistance.

Thanks
Rob

BluePanther
01-17-2012, 03:51 PM
http://www.codingforums.com/showthread.php?t=248944

This post is what you want :)

robbiez
01-17-2012, 04:14 PM
HI
thanks for the link.
I have tried implementing the multisort function but get various errors.

foreach ($_from as $this->_tpl_vars['k'] => $this->_tpl_vars['ARR_F']):
$sortColumn[] = $this->_tpl_vars['ARR_F']['depth_mm'];
array_multisort($sortColumn, SORT_ASC, $this->_tpl_vars['ARR_F']);
$this->_foreach['frchFrameList']['iteration']++;

I get this error:
Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent in

djh101
01-17-2012, 05:19 PM
That error means that the columns you are using to sort are different sizes and one or more array values have nothing to be sorted with.