I can't get past making what I think is a 2D Array in PHP. I'm using a CSV as source input and want to take one of the columns and split that into an array as well.
$csv = array_map("str_getcsv", file("data/data.csv", FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i => $row) {
$csv[$i] = array_combine($keys, $row);
$linkto = $csv[$i]['linkto'];
// $linktoArray = explode(" ", $linkto);
echo '<pre>';
// print_r($linktoArray);
echo '</pre>';
$csv[$i] = array_combine($keys, $row);
}
$csv['timestamp'] = time();
echo '<pre>';
print_r($csv);
echo '</pre>';
Will output:
Array
(
[0] => Array
(
[color] => 1
[shape] => 0
[label] => string
[size] => 1
[linkto] => 1 2 3
)...
Using something similar to what I commented out, I'd love to see something like:
Array
(
[0] => Array
(
[color] => 1
[shape] => 0
[label] => string
[size] => 1
[linkto] => Array
(
[0]=>1
[1]=>2
[2]=>3
)
)...
However, right now I'm just getting an array before my containing array. Pardon my ignorance, I haven't had much experience past the front-end. Any suggestions? I'm sure this has been explained before, but I can't find the right terminology to utilize a search.