title: Get Initials From Full Names In PHP Array
body: <p>I would like to take a list of names (from Wordpress) and get the initials and separate them by '/'.  In most cases, there will be 2 or more names.  In some cases there will be just 1 name.</p>
  <p><strong>For example:</strong></p>
  <p>John Doe<br />
  Jane Adams<br />
  Michael McDonald</p>
  <p><strong>should output:</strong>
  JD/JA/MD</p>
  <p>Here is what I have tried so far in my attempt to figure it out.</p>
  <pre><code>foreach ( $result as $user )
  {
     $user_id = $user-&gt;user_id1;
     $user = get_userdata( $user_id );
     $name[] = $user-&gt;display_name;
  }
  $comma_names =  implode('/', $name);
  
  $words = explode(&quot;/&quot;, $comma_names);
      $initials = &quot;&quot;; 
      foreach ($words as $w) {
          $initials .= $w[0];
          
      }
  
   echo $initials;
  </code></pre>
  <p>Obviously, this only outputs the first letter of each name.  Do I need to use an additional explode in my loop?</p>
  <p>What is the best way to do this?</p>