D
D
doktorr2014-10-04 20:19:29
PHP
doktorr, 2014-10-04 20:19:29

Where is the error in the foreach function?

Please help me solve the problem.
There is a $f variable with arrays
Example

Array
(
    [0] => Array
        (
            [0] => 1 2 3
        )

    [1] => Array
        (
            [0] => робот
        )

    [2] => Array
        (
            [0] => toster
        )

)

and this code should save these arrays, that's the reason it doesn't even save.
foreach ($f as $rok) {

  $trans = "".$rok.".html";

  if (file_exists($trans)) {
  } else {
    file_put_contents($trans, $rok);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Chistyakov, 2014-10-04
@doktorr

PHP Notice:  Array to string conversion in /home/sashka/test1.php on line 14

Here in this line:
It is logical - why concatenate a string with an array?
The result of such a concatenation is, by the way, the name of the file "Array.html"
Look - everything was probably saved there?
You need to change the code like this:
foreach ($f as $rok) {

  $trans = "".$rok[0].".html";

  if (file_exists($trans)) {
  } else {
    file_put_contents($trans, $rok);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question