|
King of Portal
Join Date: Sep 2005
Posts: 431
Rep Power: 4 
|
Re: Function too convoluted?
Alright Sane this is what I managed to come up with after checking out the PHP site and reading what you were saying. I didn't quite understand you at first until I found this example on the PHP site. <pre> <?php $data = array( array('volume' => 67, 'edition' => 2), array('volume' => 86, 'edition' => 1), array('volume' => 85, 'edition' => 6), array('volume' => 98, 'edition' => 2), array('volume' => 86, 'edition' => 6), array('volume' => 67, 'edition' => array( array('volume' => 67, 'edition' => 2), array('volume' => 86, 'edition' => 1), array('volume' => 85, 'edition' => 6), array('volume' => 98, 'edition' => 2), array('volume' => 86, 'edition' => 6), array('volume' => 67, 'edition' => array( array('volume' => 67, 'edition' => 2), array('volume' => 86, 'edition' => 1), array('volume' => 85, 'edition' => 6), array('volume' => 98, 'edition' => 2), array('volume' => 86, 'edition' => 6), array('volume' => 67, 'edition' => 7) )) )) ); $callback_func = create_function('$key, $value', 'return ($value < 2 || $value > 70) ? true : false;'); print_r(array_filter_multi($data, $callback_func, null)); function array_filter_multi($array, $callback, $filtered_output = ""){ $ret = array(); foreach($array as $key=>$value){ if($callback($key,$value)){ if(is_array($value)){ $ret[$key] = array_filter_multi($value, $callback, $filtered_output); }elseif(is_object($value)){ $ret[$key] = array_filter_multi(get_object_vars($value), $callback, $filtered_output); }else{ $ret[$key]=$value; } }else{ $ret[$key]=$filtered_output; } } return $ret; } ?> </pre>
__________________
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
|