Reputation: 135
I am new to PHP.
I want to convert this array [["14785"],["125478"]] to string like this 14785,125478.
What is the way to do this?
Upvotes: 2
Views: 14583
Reputation: 11987
try this,
Using implode()
- Demo
$array = ["14785"],["125478"]
$str = implode(',',$array);
echo $str;
Using join()
- Demo
$array = ["14785","125478"];
$str = join(",",$array);
echo $str;
EDIT
For multi-dimention array, - Demo
$arr = [["14785"],["125478"]];
$str = implode(',', array_map(function($el){ return $el[0]; }, $arr));
echo $str;
Upvotes: 6
Reputation: 804
Using implode()
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>
Upvotes: 0
Reputation: 4236
use php's implode
function
$arr = ["14785","125478"];
echo implode(",",$arr);
Upvotes: 5