Isit Isitira
0
Q:

array to string php


<?php

$arr = array('Hello','World!','Beautiful','Day!');

echo implode(" ",$arr);

?> 
3
print_r(explode(',',$yourstring));
0
Using implode() function in Php
-----------------------
Syntax
implode(separator,array);  

Example
<?php  
//assigning value to the array  
$dummyArr = array("Hello","Greppers,","Ankur","here !");  
  
echo implode(" ",$dummyArr);// Use of implode function  
?>  
  
Output:
Hello Greppers, Ankur here !
3

<?php

$str = "Hello world. It's a beautiful day.";

print_r (explode(" ",$str));

?> 
0
$gadget = array( 'computer', 'mobile', 'tablet' );
echo implode($arr);
1
// Use json_encode to collapse the array to json string:
$stuff = array(1,2,3);
print json_encode($stuff);   //Prints [1,2,3]
1
// use the builtin php function print_r or var_dump:
$stuff = array(1,2,3);
print_r($stuff);
$stuff = array(3,4,5);
var_dump($stuff);
1
$person = [
    'name' => 'Jon',
    'age' => 26,
    'status' => null,
    'friends' => ['Matt', 'Kaci', 'Jess']
];

echo json_encode($person);
// {"name":"Jon","age":26,"status":null,"friends":["Matt","Kaci","Jess"]}
0

New to Communities?

Join the community