PHP reads text content into a two-dimensional array

WBOY
Release: 2016-07-25 08:53:39
Original
1232 people have browsed it
  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



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!