Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function validate_select($val, $myoptions)
  2. {
  3. //print_r($myoptions);
  4. for($i=0;$i<count($myoptions);$i++){
  5. if($val==$myoptions[$i]){
  6. return $val;
  7. }
  8. }
  9. return false;
  10. }
  11.  
  12. $testVar = 'apple';
  13. $myoptions = array('banana','pear','apple');
  14. $result = filter_var($testVar, FILTER_CALLBACK, array('options' => function($var) {
  15. //return validate_select($var, array('banana','pear','apple')); //case A: returns correct value 'apple'
  16. return validate_select($var, $myoptions); //case B: returns unexpected value false
  17. }));
  18. echo($result);
  19.  
  20. $result = filter_var($testVar, FILTER_CALLBACK, array('options' => function ($var) use ($myoptions) {
  21. return validate_select($var, $myoptions);
  22. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement