Answer the question
In order to leave comments, you need to log in
How to write certain keys of a multidimensional array?
Hello. Everything was fine while writing to different files. Immediately, for some reason, each line is written 4 times. It is very difficult to google the output of multidimensional arrays, with certain keys ... Please help. I need to output the keys from each array 1 time and write them to a file.
foreach($forwr as $massiv)
{
foreach($massiv as $value)
{
$fp = fopen("/domen/file.txt", "a");
$str = $massiv["id"].",".$massiv["name"].",".$massiv["title"]."\n";
fwrite($fp, $str);
}
fclose ($fp);
}
Answer the question
In order to leave comments, you need to log in
$str = "";
foreach($forwr as $massiv) {
$str .= "{$massiv['id']},{$massiv['name']},{$massiv['title']}" . PHP_EOL;
}
file_put_contents ("/domen/file.txt", $str, FILE_APPEND);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question