title: How to use string functions to clean array variables
body: <p>I have this php code for html <code>form</code></p>
  
  <pre><code>if(isset($_POST['job_title'])){
    foreach($_POST['job_title'] as $selected) {
       $job_title[] = $selected ;
    }
    $job_title = json_encode($job_title);
    $job_title = clean_string($job_title);
  }
  </code></pre>
  
  <p>and the this is what <code>clean_string</code> function code which cleans input for SQL</p>
  
  <pre><code>function clean_string($string){
     global $connection;
     $string = trim($string);
     $string = stripslashes($string);
     $string = htmlspecialchars($string);
     $string = htmlentities($string);
     $string = mysqli_real_escape_string($connection,$string);
     return $string;
  }
  </code></pre>
  
  <p>So when this code execute it cause an error like(
  <strong>expects parameter 1 to be string, array given</strong>)</p>
  
  <p>How to solve this problem ?
  Thanks in advance</p>