I'm building a CSV import where the first row is the column names of everything else. Instead of having $row[0]
I'd like to use $row['id']
to keep the code readable and make it easier for future developers. The problem is... I can't think of an efficient way to do this...
while (($current = fgetcsv($handle, 1000, "\t")) !== false) {
if ($row == 0) {
}
}
The only methods I can think of require a bit of legwork and I'd like t开发者_如何学Pythono just have a simple solution that's clean and easy (every developers dream, I know). So I thought I'd post here and see if someone had a better method than what I'm thinking...
Nevermind... just found array_combine on PHP.net... it looks like exactly what I need
<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
print_r($c);
?>
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)
I'd delete my question but I think this would be useful for some people to know...
精彩评论