explode returns an array. How to make explode work inside an array?

Listing file.dat is like this:

 string=8:1 string=15:1 string=26:1 string=30:10 string=18:10 string=2:10 

We read the file file.dat :

 $dat = file('file.dat'); $dat = str_replace(":", "=", $dat); // где то тут всаживаем explode(); $count = count($dat); for($i = 0; $i < $count; $i++) { echo $dat[$i] . '<br />'; // string=8:1 нужно получить как [0] [1] [2] } 

    2 answers 2

    If I understood correctly, then somehow ...

      $data = explode("\r\n", $data); $dataLength = count($data); for($i=0; $i<$dataLength; $i++) { $type = explode('=',$data[$i]); $values = explode(':', $type[1]); $result[$i][0] = $type[0]; $result[$i][1] = $values[0]; $result[$i][2] = $values[1]; } print_r($result); //на выходе массив массивов со значениями // 0 - string, 1 - первое число, 2 - второе 
    • Because in this case, the lines are divided only into two parts, then for explode() it is desirable to use the 3rd parameter $limit . - Ilya Pirogov

    One of the many pages that I visit regularly, and I almost remember by heart already:

    Array Functions

    Perhaps you will help.