hawkinscanary
New Member
Consider the functions \[code\]sort\[/code\] and \[code\]array_reverse\[/code\].Why does one modify the variable passed, whereas the other return a new version?\[code\]$a = array(3, 1, 2);sort($a);// $a === array(1, 2, 3)array_reverse($a);// $a === array(1, 2, 3)\[/code\]\[code\]sort\[/code\] could just as easily been written to return a modified copy of the argument, and vice-versa for \[code\]array_reverse\[/code\].The reason I'm asking is because I want to know if there's any guidelines for deciding whether write functions using the "pass-by-reference and modify" approach vs the "pass-by-value, modify and return" approach.