Jump to content

Array to file?!


benbraggs13

Recommended Posts

Hey guys,

 

First post here! Just looking for a bit of help.

 

Have an array of data and i want to use fwrite to write all it's contents to a file. Is this possible?

 

I have

 

$fp = fopen($local_file, "w") or die ("Can't open file $local_file");
fwrite($fp, $myArray);
fclose($fp);

 

Which doesn't work.. any ideas? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/53281-array-to-file/
Share on other sites

not tested dont no if it works.

<?php

$x=array("i","love","php");

foreach($x as $myArray){

$fp = fopen($local_file, "w") or die ("Can't open file $local_file");

fwrite($fp, $myArray);

fclose($fp);
}

?>

 

sorry corrected cheers

 

<?php

$x=array("i","love","php");

$fp = fopen($local_file, "w") or die ("Can't open file $local_file");

foreach($x as $myArray){

fwrite($fp, $myArray);

}

fclose($fp);


?>

Link to comment
https://forums.phpfreaks.com/topic/53281-array-to-file/#findComment-263293
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.