0

I have array structure like this,

Array
(
    [1] => Array
        (
            [1] => 
            [2] => 
            [3] => 
            [4] => Product
            [5] => Product Name
            ..
            [59] => Color
        )

    [2] => Array
        (
            [1] => 
            [2] => 
            [3] => 1
            [4] => 9155
            ....
            [59] => 
        )

    [3] => Array
        (
            [1] => 
            [2] => 
            [3] => 1
            [4] => 9165
            ...
            [59] => Green
        )

    [4] => Array
        (
            [1] => 
            [2] => 
            [3] => 
            [4] => 
           ...
            [58] => 
            [59] => 
        )
        )

Its reading data from Excel sheets , the issue is when i read data from excel sheet it reads empty rows too, I already tried to ignore empty rows from the excel sheet some how its working (when the excel is created from MSexcel ) but from Google Drive its reading empty rows. So I would like to remove those rows with 1- 59 are blanks. in the above example array with index 4 .

Note that some index have missing values in many sub index but I don't want to remove those, only all sub indexes from 1-59 are blank then that main index (here its 4) needs to remove.

Is there any smart way to remove those array index that have empty values. I not like to iterate all the array and store to another.

1

4 Answers 4

2

if you want to remove the index 4 that is an empty array :

array_filter(array_map('array_filter', $array)); 
Sign up to request clarification or add additional context in comments.

Comments

2

Use array_map

$array = array_map('array_filter', $array);

1 Comment

its not removing the index 4 its self just removing sub indexes ?
1

let try with array_filter

$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => ''
          );

print_r(array_filter($entry));

Array
(
    [0] => foo
    [2] => -1
)

Comments

0

Use array_filter..It will remove all empty values..

array_filter($array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.