title: can you use a function to save lines during an ajax call?
body: <p>Apologies if I didn't quite word my title correctly. I am currently finishing up this Wordpress AJAX challenge in which we needed to display particular user-types to the screen depending on a plugin's selection. The function below is whats being called in my AJAX call. I currently am running multiple instances of this code below, one for each user-type:</p>
  <pre><code>$user_roles = get_option( 'show_users' );
  $count = 0;
  
  if($user_roles['administrator']) {
  
      $users = get_users( array (
          'role' =&gt; 'administrator'
      ));
  
      foreach ($users as $user) {
          $result[$count] = $user-&gt;display_name;
          $count++;
      }
  
  }
  </code></pre>
  <p>However, I thought I might be able to create a function that can save me some code (and maybe even use a foreach later to save even more), but the code does not seem to work. Function I tried using (followed by calling the function) :</p>
  <pre><code>function save_time ($x) {
      if ($user_roles[$x]) {
          $users = get_users( array (
              'role' =&gt; $x
          ));
  
          foreach ($users as $user) {
              $result[$count] = $user-&gt;display_name;
              $count++;
          }
      }
  }
  
  save_time('administrator');
  </code></pre>
  <p>Is there something I can do make this work? Am I forgetting how functions work in general? Thank you!</p>