way2real Posted November 8, 2010 Share Posted November 8, 2010 I have following in a csv file: sku,quantity,price ---------------------- ML2225-1/4,10,38.77 ML2225-1/4,20,36 ML2225-1/4,30,33.23 ML2225-5/16,10,35.94 ML2225-5/16,20,33.37 ML2225-5/16,30,30.8 ML2225-3/8,10,34.37 ML2225-3/8,20,31.92 ML2225-3/8,30,29.46 ML2225-7/16,10,34.37 ML2225-7/16,20,31.92 ML2225-7/16,30,29.46 ML2225-1/2,10,34.37 ML2225-1/2,20,31.92 ML2225-1/2,30,29.46 ... I am able to read the file (fgetcsv). How do I build an array for each unique sku set, then do something, then continue to the next unique sku set? Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/218121-loop-through-an-array/ Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 try <?php $handle = fopen('test.csv', 'r'); while ($line = fgetcsv($handle)) $out[$line[0]][$line[1]] = $line[2]; print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218121-loop-through-an-array/#findComment-1131833 Share on other sites More sharing options...
way2real Posted November 9, 2010 Author Share Posted November 9, 2010 Thank you Sasa. I appreciate the quick response. Maybe I should have included more information. I am having a tough time wrapping my head around this and how to get it to work for what I have in mind. Using the csv file from the earlier post, the below is what I would like to accomplish: <?php $sku = 'ML2225-1/4'; $tierPrices = array(); //first tier price $tierPrices[] = array( 'qty' => 10, 'price' => 38.77 ); //second tier price $tierPrices[] = array( 'qty' => 20, 'price' => 36.00 ); //third tier price $tierPrices[] = array( 'qty' => 30, 'price' => 33.23 ); // save the tier prices $proxy->call('tierprice.update', array('ML2225-1/4', $tierPrices)); //LOOP THROUGH THE LIST TO PROCESS EACH UNIQUE SKU //ML2225-5/16 WOULD BE NEXT, THEN //ML2225-3/8, ETC. ?> I appreciate any thoughts. Quote Link to comment https://forums.phpfreaks.com/topic/218121-loop-through-an-array/#findComment-1132047 Share on other sites More sharing options...
sasa Posted November 9, 2010 Share Posted November 9, 2010 try <?php $handle = fopen('test.csv', 'r'); while ($line = fgetcsv($handle)) $out[$line[0]][] = array('qty' =>$line[1], 'price' => $line[2]); foreach ($out as $aku => $tierPrices) $proxy->call('tierprice.update', array($aku, $tierPrices)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218121-loop-through-an-array/#findComment-1132136 Share on other sites More sharing options...
way2real Posted November 9, 2010 Author Share Posted November 9, 2010 Perfect. Thank you Sasa. I really appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/218121-loop-through-an-array/#findComment-1132233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.