Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    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!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •