Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2012, 03:42 PM   PM User | #1
robbiez
New Coder

 
Join Date: Jul 2008
Posts: 70
Thanks: 8
Thanked 0 Times in 0 Posts
robbiez is an unknown quantity at this point
Sort foreach statement

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
robbiez is offline   Reply With Quote
Old 01-17-2012, 03:51 PM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
http://www.codingforums.com/showthread.php?t=248944

This post is what you want
__________________
Useful function to retrieve difference in times
The best PHP resource
A good PHP FAQ
PLEASE remember to wrap your code in [PHP] tags.
PHP Code:
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button 
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
BluePanther is offline   Reply With Quote
Old 01-17-2012, 04:14 PM   PM User | #3
robbiez
New Coder

 
Join Date: Jul 2008
Posts: 70
Thanks: 8
Thanked 0 Times in 0 Posts
robbiez is an unknown quantity at this point
HI
thanks for the link.
I have tried implementing the multisort function but get various errors.
PHP Code:
 foreach ($_from as $this->_tpl_vars['k'] => $this->_tpl_vars['ARR_F']):
$sortColumn[] = $this->_tpl_vars['ARR_F']['depth_mm'];
array_multisort($sortColumnSORT_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
robbiez is offline   Reply With Quote
Old 01-17-2012, 05:19 PM   PM User | #4
djh101
Regular Coder

 
djh101's Avatar
 
Join Date: May 2009
Location: Santa Clarita
Posts: 603
Thanks: 48
Thanked 63 Times in 63 Posts
djh101 is an unknown quantity at this point
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.
__________________
"Yeah science!"
Online Science Tools
djh101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:03 PM.


Advertisement
Log in to turn off these ads.