Link to home
Start Free TrialLog in
Avatar of locke2005
locke2005Flag for Brazil

asked on

code interpretation

Please, tell me how the attached code snippet works!
function sortArrayByField
        (
            $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;
        }

Open in new window

Avatar of ddrudik
ddrudik
Flag of United States of America image

It is described here:
http://us.php.net/manual/en/function.sort.php#76602
As well, it has the author's e-mail address if you would like further details.
Avatar of locke2005

ASKER

$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");

What are the keys in this array?
What are the values in this array?
What are the fields in this array?
Where is a PHP glossary with key, value and field?
Can you give me an example of array with key, value and field?
ASKER CERTIFIED SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I didn't try to contact the author. Do PHP.net comment authors really help???
I believe it's always worth a shot to ask someone who puts their e-mail address with their comments.

Thanks for the question and the points.