benbraggs13 Posted May 28, 2007 Share Posted May 28, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/53281-array-to-file/ Share on other sites More sharing options...
redarrow Posted May 28, 2007 Share Posted May 28, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53281-array-to-file/#findComment-263293 Share on other sites More sharing options...
trq Posted May 28, 2007 Share Posted May 28, 2007 Don't open the file within the loop. <?php $fp = fopen($local_file, "w") or die ("Can't open file $local_file"); foreach($myArray as $val) { fwrite($fp, $val); } fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53281-array-to-file/#findComment-263294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.