Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. $csv = new SplFileObject("php://filter/read=convert.iconv.cp932.utf-8/resource=sample.csv", "r");
  2. $csv->setFlags(SplFileObject::READ_CSV | SplFileObject::DROP_NEW_LINE);
  3. $columns = array(
  4. 0 => 'id',
  5. 2 => 'name',
  6. 3 => 'deleted'
  7. );
  8. foreach ($csv as $row) {
  9. $user = Users::save(
  10. array_combine(
  11. array_values($columns),
  12. array_map(function($i) use($row) {return $row[$i];}, array_keys($columns))
  13. )
  14. );
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement