php数组:如何将数组转换为字符串?

I have an array like this :

[Code] => Array
    0 => array (
        [Nom] => NameVille
        [CodeI] => 38
    )
    1 => array (
        [Nom] => NameVille2
        [CodeI] => 39
    )

And i want to print data like this :

Name : NameVille, NameVille2

Code : 38,39

how can i do that ? thankss

Use this code

<?php

  $array = [
     ['Nom'=>'NameVille','CodeI'=> 38],
     ['Nom'=>'NameVille2','CodeI'=> 39],
  ];
 $name = "";
 $code = "";
 foreach($array as $key => $value){
     $name .= $value['Nom'] . ", ";
     $code .= $value['CodeI'] . ", ";
 }

 echo "Name :".$name;
 echo "code :".$code;

?>

You can use array_column & implode together.

echo implode(',', array_column($your_array, 'Nom'));
echo implode(',', array_column($your_array, 'CodeI'));

Check Demo

array_column will return an array with the values in that column. And implode will concatenate them with ,.

This will do:

echo join(', ', array_map(function($element){return $element['Nom'];}, $arr));
echo join(', ', array_map(function($element){return $element['CodeI'];}, $arr));