Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Filtering multiple variables

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 133
    Comment on it

    Here we will learn how to filter multiple variable using the filter_var_array() function.It returns an array of values for all the requested variables else it will return FALSE if failed.


    Example

    $abcd = array
      (
      "firstname" => "ravi",
      "lastname" => "kumar",
      "age" => "36",
      "email" => "ravi@yopmail.com",
      );
    
    $filter_all = array
      (
      "firstname" => array
        (
        "filter"=>FILTER_CALLBACK,
        "flags"=>FILTER_FORCE_ARRAY,
        "options"=>"ucwords"
        ),
         "lastname" => array
        (
        "filter"=>FILTER_CALLBACK,
        "flags"=>FILTER_FORCE_ARRAY,
        "options"=>"ucwords"
        ),
      "age" => array
        (
        "filter"=>FILTER_VALIDATE_INT,
        "options"=>array
          (
          "min_range"=>1,
          "max_range"=>100
          )
        ),
      "email"=> FILTER_VALIDATE_EMAIL,
      );
    
    echo '<pre>'; print_r(filter_var_array($abcd, $filter_all));
    

    OUTPUT:

    Array ( [firstname] => Ravi [lastname] => Kumar [age] => 36 [email] => ravi@yopmail.com )

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: