Search code examples
phpfwrite

Writing to file based on array value


I have created an array which contains;

  1. The filepath where the item is to be written.
  2. the contents that I wish to be written to the file

The code for my array is:

foreach ($NewLang as $row => $val)
{
    $writefile = implode(",", $val);

    $filepath = $val[0];
}

This will display something like this:

basket.lang.php,LANG_BASKETUPDATED,Basket Updated,

My question is how can I use file_put_contents() to write each line based on the value stored in $val[0]?


Solution

  • Solved this by creating a function for writing the files and placing it in the foreach loop instead.

    Now my foreach loop looks like this:

    foreach ($NewLang as $row => $val)
    {   
        {   
            append_define($val[0], $val[1], $val[2]);
        }
    }