modify array multi dimensional php

2185 views php
7

this is my script

$cellValues3 = $objPHPExcel->getActiveSheet()->rangeToArray("$columnName$startRow:$highestColumn2$lastRow");
foreach ($cellValues3 as $value){
    $wh[]=$value;

}

echo "<pre>";
    print_r($wh);
echo "</pre>";die();

This is result array:

https://ibb.co/kgcaBe

but I want to result array

https://ibb.co/dLP8Ez

Please help me, I very confuse make array. Thanks

answered question

2 Answers

10

So, you need to replace some keys in $value array. You can do it this way, for example:

foreach ($cellValues3 as $value){
    $first_item = array_shift($value);
    $second_item = array_shift($value);

    $wh[] = [
        'initial' => $first_item,
        'nopol' => $second_item,
        'ws' => $value,
    ];
}

posted this
0

You could modify the foreach loop and use array_shift() to get each 1st and 2nd array item :

    foreach ($cellValues3 as $key=>$value){
                $wh[$key]['initial']=array_shift($value);
                $wh[$key]['nopol']=array_shift($value);
                $wh[$key]['ws']=$value;

            }

            echo "<pre>";
                print_r($wh);
            echo "</pre>";die();

posted this

Have an answer?

JD

Please login first before posting an answer.