note 80385 modified in function.array-search by danbrown

From: Date: Wed, 29 Apr 2009 12:55:44 +0000
Subject: note 80385 modified in function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153970@lists.php.net to get a copy of this message
Just adding my two penneth to someone else's script from below. If you need to easily index your csv use this slightly modified script to parse a csv file into an associative array 2d, indexed by the first column value <?php function buildStock($File) { $handle = fopen($File, "r"); $fields = fgetcsv($handle, 1000, ","); while($data = fgetcsv($handle, 1000, ",")) { $detail[] = $data; } echo "details"; var_dump($detail); echo "<br />"; $x = 0; $y = 0; foreach($detail as $i) { foreach($fields as $z) { //original code //$stock[$x][$z] = $i[$y]; $stock[$i['0']][$z] = $i[$y]; $y++; } $y = 0; $x++; } return $stock; } var_dump(buildStock("conf.csv")); ?> --was-- Just adding my two penneth to someone else's script from below. If you need to easily index your csv use this slightly modified script to parse a csv file into an associative array 2d, indexed by the first column value function buildStock($File) { $handle = fopen($File, "r"); $fields = fgetcsv($handle, 1000, ","); while($data = fgetcsv($handle, 1000, ",")) { $detail[] = $data; } echo "details"; var_dump($detail); echo "<br />"; $x = 0; $y = 0; foreach($detail as $i) { foreach($fields as $z) { //original code //$stock[$x][$z] = $i[$y]; $stock[$i['0']][$z] = $i[$y]; $y++; } $y = 0; $x++; } return $stock; } var_dump(buildStock("conf.csv")); http://php.net/manual/en/function.array-search.php

« previous php.notes (#153970) next »