<?php $strings = ["v", 'g', 'a']; sort($strings); print_r($strings); ?> 

This code displays

 Array ( [0] => a [1] => g [2] => v ) 

and how to make it output а, g, v ?

    3 answers 3

    instead

     print_r ($strings); 

    use

     echo join(",",$strings); 

    and yes, sort works))

    • 2
      Thank you for your kindness! - Sad
    • one
      join is considered "deprecated", code analyzers recommend using implode with the same syntax - Dmitry Kozlov
    • I use join it is shorter and more obvious imho though earlier yuzal implode - sterx
    • @ New Life Thank you for your kindness! It is better to mark the answer as a solution to the problem. Left tick - Dmitry Kozlov
     <?php $strings =["v", 'g', 'a']; sort($strings); for($i = 0; $i < count($strings); $i++){ echo $strings[$i]; } ?> 

      As an option using implode ( http://php.net/manual/ru/function.implode.php ):

       $strings = ["v", 'g', 'a']; sort($strings); $strings = implode(",", $strings); print_r($strings);