PHP 的 save()
函數本身不支持多種格式,但你可以使用其他庫或方法來實現多種格式的保存。例如,如果你想要將數據保存為 CSV、JSON 或 XML 格式,你可以使用以下方法:
$data = [
['name' => 'John', 'age' => 30],
['name' => 'Jane', 'age' => 28]
];
$csv = fopen('output.csv', 'w');
foreach ($data as $row) {
fputcsv($csv, $row);
}
fclose($csv);
$data = [
['name' => 'John', 'age' => 30],
['name' => 'Jane', 'age' => 28]
];
header('Content-Type: application/json');
echo json_encode($data);
$data = [
['name' => 'John', 'age' => 30],
['name' => 'Jane', 'age' => 28]
];
$xml = new SimpleXMLElement('<root/>');
foreach ($data as $row) {
$person = $xml->addChild('person');
$person->addChild('name', $row['name']);
$person->addChild('age', $row['age']);
}
header('Content-Type: application/xml');
echo $xml->asXML();
根據你的需求,你可以選擇合適的方法將數據保存為多種格式。