View Single Post
Old Feb 1st, 2008, 10:33 AM   #13
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Function too convoluted?

Figured it out Sane, rather than doing it that way you would use call_user_func. So that array_filter_multi would become
PHP Syntax (Toggle Plain Text)
  1. function array_filter_multi($array, $callback, $filtered_output = ""){
  2. $ret = array();
  3. foreach($array as $key => $value){
  4. if([i]call_user_func($callback, $key, $value)[/i]){
  5. if(is_array($value)){
  6. $ret[$key] = array_filter_multi($value, $callback, $filtered_output);
  7. }elseif(is_object($value)){
  8. $ret[$key] = array_filter_multi(get_object_vars($value), $callback, $filtered_output);
  9. }else{
  10. $ret[$key] = $value;
  11. }
  12. }else{
  13. $ret[$key] = $filtered_output;
  14. }
  15. }
  16. return $ret;
  17. }
Then you could just write a function such as
PHP Syntax (Toggle Plain Text)
  1. function comparator($key, $value){
  2. return $key < $value;
  3. }
And finally pass it to the previous function by doing the following
PHP Syntax (Toggle Plain Text)
  1. array_filter_multi($data, "comparator", null);
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote