Skip to content

Instantly share code, notes, and snippets.

@4lb0
Created March 6, 2015 14:34
Show Gist options
  • Save 4lb0/d61ea7006010afe685c9 to your computer and use it in GitHub Desktop.
Save 4lb0/d61ea7006010afe685c9 to your computer and use it in GitHub Desktop.
<?php
$csv = array(
array('Jose', 'jose@tectonica.com', 'Buenos Aires, Argentina'),
array('Albo', 'albo@pragmore.com', 'New York, USA'),
);
$_POST['columns'] = array('firstname', 'email', 'location');
$columns = $_POST['columns'];
$csvOrdered = array();
foreach ($csv as $row) {
$rowOrdered = array();
foreach ($columns as $position => $key) {
$rowOrdered[$key] = $row[$position];
}
$csvOrdered[] = $rowOrdered;
}
var_dump($csvOrdered);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment