How does this code work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raistlin Majere

    How does this code work?

    // Please, tell me in details.

    function sortArrayByFiel d
    (
    $original,
    $field,
    $descending = false
    )
    {
    $sortArr = array();

    foreach ( $original as $key =$value )
    {
    $sortArr[ $key ] = $value[ $field ];
    }

    if ( $descending )
    {
    arsort( $sortArr );
    }
    else
    {
    asort( $sortArr );
    }

    $resultArr = array();
    foreach ( $sortArr as $key =$value )
    {
    $resultArr[ $key ] = $original[ $key ];
    }

    return $resultArr;
    }
  • Michael Fesser

    #2
    Re: How does this code work?

    ..oO(Raistlin Majere)
    >// Please, tell me in details.
    It works good. SCNR

    Any particular problems in understanding the code? The used statements
    and functions are pretty straightforward . Basic PHP, nothing special.
    So where are your difficulties?

    Micha

    Comment

    Working...