• PHP Display array data

    MarkGrillo Member

    I have been trying to figure this out and had no success. Had a look online and found nothing.

    I have an array:

    
    

    Could anyone tell me what function i have to use so they just display like this:

    James, Tim, Mark and John
    
  • SapnaVishwas Member

    You need the implode function. More info here:

    http://php.net/manual/en/function.implode.php

    Use it like this:

    echo implode(",", $names);

  • Adan Member

    Here’s a solution…

     $name)
    {
       switch($key)
       {
          case count($names)-2:
          $seperator = ' and ';
          break;
    
          case count($names)-1:
          $seperator = '';
          break;
    
          default:
          $seperator = ', ';
          break;
       }
       echo $name.$seperator;
    }
    
  • Abhey Member

    This will do exactly what you want

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish