Define 2D array with loops in php

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-06-10T15:31:41Z Indexed on 2010/06/10 15:32 UTC
Read the original article Hit count: 183

Filed under:
|
|
|
|

I have an array $rows where each element is a row of 15 tab-delimited values. I want to explode $rows into a 2D array $rowData where each row is an array element and each tab-delimited value is assigned to a different array element. I've tried these two methods without success. I know the first one has a coding error but I do not know how to correct it. Any help would be amazing.

for ($i=0; $i<count($rows); $i++){
    for ($j=0; $j<15; $j++){
    $rowData = array([$i] => array (explode("   ", $rows[$j])));
    }  
}  

foreach ($rows as $value){
    $rowData = array( array (explode("  ", $rows[$value])));  
}

© Stack Overflow or respective owner

Related posts about php

Related posts about array