Home>
foreach ($filearr as $no =>$val) {
$cols = explode (",", $val);
$keyval = explode ("=", $cols [0]);
if ($keyval [1] == $ID) {
continue;
} else {
$newLines [] = $val;
}
}
$fp = fopen ("product.txt", "a");
fwrite ($fp, $newLines []);
fclose ($fp);
Fatal error: Cannot use [] for reading in
I get an error. How can I write it?
-
Answer # 1
-
Answer # 2
fwrite ($fp, implode (PHP_EOL, $newLines));
-
Answer # 3
fwrite ($fp, $newLines [0]);
Now
Related articles
- php - i want to page the array data with laravel8
- php - how to write sql values
- i want to know how to extract words from a sentence and make them into an array in php
- php - i want to be able to use the validate function
- i want you to see the error contents of php
- php - url parameters? i want to get the slug name from
- php - i want to give the key value of a multidimensional array to the value of the array
- php - i want to expand and display a nested array in view
- php - i want to remove commas from the data in $this-> data
- php - i don't know where to write pdoexception in the mvc model
- creating an associative array using php and variable names as keys
- javascript php array
- i want to pass the php path
- php - i want to display array values on an html table in laravel
- php - a method to display an array in a table
- i want to create a form using html and php
- php - i want to install http_request2 of pear on ec2 of aws
- php - about laravel's associative array
- php - about array curly braces
- php - i want to get the file size of a blob file stored in the database
Trends
The second argument of fwrite () takes a String type.
Please check the usage manual first. (php.net) fwrite
$newLines
is an array of strings, soMethod 1
Write this after concatenating it with a line feed code (
\ r \ n
) usingimplode ()
.(php.net) implode
Method 2
Loop with
$newLines
elements inforeach
orfor
, and writefwrite ()
for each line Please give me.