Home>
id = 1, product = Chair
id = 2, product = pencil
$filearr = file ('send.txt');
foreach ($filearr as $no) {
  echo $no;
 }

In the above code, you can get anything other than id. How can I get only the id part?

php
  • Answer # 1

    $filearr = file ('file.txt');
    foreach ($filearr as $no) {
      if (preg_match ("/ (?<= ^ id =) \ d + /", $no, $match)) {
        echo $match [0];
      }
    }

  • Answer # 2

    File is used, so it is not in the associative array in the first place.

    It needs to be extracted in some way.

    Since the specification is unknown, it's messy, but it looks like the following.