文件助手:将数组写入文件?

It seems I can't write an array with file helper.

write_file('./save/' . $fileName . '.php', $array, 'w+')

Severity: Warning

Message: fwrite() expects parameter 2 to be string, array given

Filename: helpers/file_helper.php

Line Number: 96

Is there anyway around this?

Different ways to do that. As the error message is telling you, you'll need a string to store the data. You can use serialize() to store the value. When you want to use it again as an array, you can use unserialize().

write_file('./save/' . $fileName . '.php', serialize($array), 'w+')

Edit:

Since it apparently does not work well in CI, according to @flux, the code needs to be divided:

$serialized = serialize($array);
write_file('./save/' . $fileName . '.php', $serialized, 'w+')

instead of implode you could do something like this

write_file('./save/' . $fileName . '.php', print_r($array,true), 'w+');

where print_r with second parameter -> true will return the printed array as string and save it in your file. However, with this function, unlike serialize, you won't be able to reuse the array again.