Home  >  Article  >  Backend Development  >  PHP reads text content into a two-dimensional array

PHP reads text content into a two-dimensional array

WBOY
WBOYOriginal
2016-07-25 08:53:391270browse
  1. $content=file_get_contents("myfile.txt");
  2. $array = explode("rn", $content);
  3. $data =array();
  4. foreach ($array as $row) {
  5. $data[] = explode("||", $row);
  6. }
  7. for($i=0;$i$a=$data [$i][0];
  8. $b=$data[$i][1];
  9. echo "$a && $b
    ";
  10. }
  11. ?>
Copy code

illustrate: Read the contents of myfile.txt Split the read content with newlines and assign it to the array $array Define $data as an array Traverse the $array array, split it with || and assign it to the $data array Output all values ​​in $data array



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn