Code 'nicely' an output from an array (foreach with use of substr)

Frederic CS asked
php arrays string export
via

i would like to write ‘nicely’ when i code the use of an array content to make a string.

$array=['21260','777','32'];


foreach($array as $value)
  $tmp=$tmp.$value."','";

$FINALE_STRING="('".substr($tmp,0,strlen($tmp)-2)).")";
// the FINALE_STRING SHOULD BE THAT:   $FINALE_STRING="('21260','777','32')"

Thx for improving me.


Answer
via

You can do this using implode().

<?php
$array = ['21260','777','32'];
$final_string = "('".implode("','", $array)."')";
Share This
Posted in: