A
A
Aidar2017-06-24 22:01:51
PHP
Aidar, 2017-06-24 22:01:51

How to get specific values ​​from an array?

Hello! This is how I output the csv file to an array.

<?php

$csvArray = array();

$csvData = file_get_contents('file.csv');

$lines = explode(PHP_EOL, $csvData);

foreach ($lines as $line) {

    $csvArray[] = str_getcsv($line);

}
echo '<pre>';
 print_r($csvArray);
echo '</pre>';
?>

And it turns out this kind of
072c9600cf164a01888643a0de1779cb.PNG
Question. How can I finally display only the first values ​​​​from the array (they are underlined in the picture)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D3lphi, 2017-06-24
@D3lphi

In your example, the str_getcsv() function is completely useless. Your separator is a semicolon, and the str_getscv() function works with a comma separator by default. Change
to After the action, the elements will be divided as needed, and as a result, you can get the first element in this way: $csvArray[0][0] $csvArray[0][1] and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question