I
I
ILoveYAnny2016-03-24 22:49:56
PHP
ILoveYAnny, 2016-03-24 22:49:56

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

1 answer(s)
I
Immortal_pony, 2016-03-24
@ILoveYAnny

$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 question

Ask a Question

731 491 924 answers to any question