phpzend-gdata

trying to figure out how to fill array in php


guys not native english speaker, so im trying my best to explain my question here

    foreach($columnFeed as $cellEntry){
    $result[$cellEntry->cell->getColumn()] = $cellEntry->cell->getText();
}

that piece of code fills me an array with rows and values row => value,,, now using zend g data, if a cell is empty it simply wont return anything, like in row 112 col 4, if its empty, nothing will be displayed, i need to assign a value to that key value in particular IF its empty , in a for loop or a foreach maybe,

i can do it like this right now

if(!isset($result[14]))
{
    $result[14] = "0:00";
    echo $result[14];
}

it outputs position 14 of $result as 0:00 correctly, but as you can see it is not the best way since i will be having columns from #1 to #14 , and some cases more, i would end up having tons of if statements,,,

i tried doing it this way

foreach($result as $key => $value) 
{
    if(!isset($result[$key]))
    {
        $result[$value] = "0:00";
    }
}

i know somethings wrong, but cant figure out what is, coud someone please point me in the right direction maybe with the correct term of what i need to search or something like that.

after all that the $result[$value here] will be used in some array like this

    $data = array (
    'in' => $result[number of index],
    'out' => $result[number of index]
);

to fill up a google spreadsheet using zend gdata.


Solution

  • With isset() you are checking for !isset($result[$key]) with $key and assigning with variable $value as index to $result[$value] = "0:00"; hence value not setting properly. Please make following changes in our code If you want value in $key to be set as index of $result.

    foreach($result as $key => $value) 
    {
        if(!isset($result[$key]))
        {
            $result[$key] = "0:00";
        }
    }