PHP Warning: Array to string conversion code example

Example 1: Array to String Conversion in PHP

$gadget = array( 'computer', 'mobile', 'tablet' );
echo implode($arr);

Example 2: php Array to string conversion

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 !

Example 3: Notice: Array to string conversion php

// Use json_encode to collapse the array to json string:
$stuff = array(1,2,3);
print json_encode($stuff);   //Prints [1,2,3]

Example 4: Notice: Array to string conversion php

$stuff = array(1,2,3);
print_r($stuff);
$stuff = array(3,4,5);
var_dump($stuff);

Tags:

Php Example