-1

I have a list of arrays below

Array
(
    [0] => name
    [1] => age
    [2] => class
    [3] => number
)
Array
(
    [0] => jhon
    [1] => 24
    [2] => 1
    [3] => 99
)
Array
(
    [0] => ali
    [1] => 25
    [2] => 2
    [3] => 100
)
Array
(
    [0] => smith
    [1] => 30
    [2] => 10
    [3] => 109
)

I am trying to extract the information of an xlsx file from the following code and using a library, but I want to delete the titles in this file

I use the following code for this

$file = $_FILES['excel']['tmp_name'];
        $xlsx = SimpleXLSX::parse($file);
        
        foreach( $xlsx->rows() as $r ) {
            unset($r[0]);
            print_r($r);
        }

But this delete cell 0 of all arrays,I want to delete the following array

Array
(
    [0] => name
    [1] => age
    [2] => class
    [3] => number
)
zvi
  • 3,032
  • 1
  • 23
  • 40
  • https://stackoverflow.com/questions/369602/deleting-an-element-from-an-array-in-php this may help – lozo Apr 24 '22 at 19:45
  • Does this answer your question? [Deleting an element from an array in PHP](https://stackoverflow.com/questions/369602/deleting-an-element-from-an-array-in-php) – Keyvan Gholami Apr 24 '22 at 19:55

1 Answers1

0

You can do it by checking when is the first row.

$file = $_FILES['excel']['tmp_name'];
$xlsx = SimpleXLSX::parse($file);
$foreach ($xls->rows() as $k => $r) {
    if ($k === 0) {
        $header_values = $r;
        continue;
    }
    print_r($r);
}

See longer example here - https://github.com/shuchkin/simplexls/blob/master/examples/02-rows_with_header_values_as_keys.php

zvi
  • 3,032
  • 1
  • 23
  • 40