1Using implode() function in Php
2-----------------------
3Syntax
4implode(separator,array);
5
6Example
7<?php
8//assigning value to the array
9$dummyArr = array("Hello","Greppers,","Ankur","here !");
10
11echo implode(" ",$dummyArr);// Use of implode function
12?>
13
14Output:
15Hello Greppers, Ankur here !
1phpCopy<?php
2 $array = ["Lili", "Rose", "Jasmine", "Daisy"];
3 $JsonObject = json_encode($array);
4 echo "The array is converted to the Json string.";
5 echo "\n";
6 echo"The Json string is $JsonObject";
7?>
8
1$person = [
2 'name' => 'Jon',
3 'age' => 26,
4 'status' => null,
5 'friends' => ['Matt', 'Kaci', 'Jess']
6];
7
8echo json_encode($person);
9// {"name":"Jon","age":26,"status":null,"friends":["Matt","Kaci","Jess"]}
10
1phpCopy<?php
2 $array = ["Lili", "Rose", "Jasmine", "Daisy"];
3 $JsonObject = serialize($array);
4 echo "The array is converted to the Json string.";
5 echo "\n";
6 echo"The Json string is $JsonObject";
7?>
8
1// Use json_encode to collapse the array to json string:
2$stuff = array(1,2,3);
3print json_encode($stuff); //Prints [1,2,3]