02-02-2010, 05:27 AM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
There are two issues with the script are preventing it from working. The first is that you can not simply print an array as is, arrays reference to places in memory that hold your values. You have to go though each element of the array and write the value to the file. The other issue is that you were passing the array by value, since arrays reference memory opposed to directly holding a value, you need to pass that reference. The following works, since I didn't want to mess around with the SQL, I assigned the array by hand.
PHP Code:
<?php $myFile = "test.txt"; $fh = fopen($myFile, 'w') or die("can't open file");
function data_dump( $query ) { $data[] = "Hello"; $data[] = "World"; $data[] = "Again"; $data[] = "Dummy"; $data[] = "content";
return $data; }
$stringData = &data_dump( $query )."\n";
foreach($stringData as $value) { fwrite($fh, $value); } fclose($fh); ?>
My explaination probably did not make sense and certianly did not do the topic justice. Look up "PHP pass by reference" on Google and have a read through this thread if you want some further clarification.
|
|
|
|