Home > Blockchain >  how to delete first array in multi array
how to delete first array in multi array

Time:04-25

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
)

CodePudding user response:

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

  •  Tags:  
  • php
  • Related