To convert an Array to JSON in PHP, we use json_encode() function. The function is used to encode a value to JSON format $arr = array ( 'Millie' => 'Eleven' , 'Mike' => 'Finn' , 'Gaten' => 'Dustin' , 'Noah' => 'Will' ); echo json_encode ( $arr ). " \n " ; Output : { "Millie" : "Eleven" , "Mike" : "Finn" , "Gaten" : "Dustin" , "Noah" : "Will" }
Write the content to a file in PHP We can write the contents to the file using fopen() function in PHP .fopen in write mode opens the file to write the content to file $fw = fopen('test.html', "w"); fwrite($fw, $s); fclose($fw);