Page 1 of 1

Read and Split into Many variables

Posted: Tue Jul 06, 2010 10:27 am
by ChrisK
I have a file named sku.txt with SKU number in each line. File may contains from 1 SKU to 100 SKU's. I need to read this file and split in to variables for every 10 SKU numbers.

if file has 5 sku numbers, then skuvar1 = 5 sku numbers
if file has 19 numbers, then skuvar1 = 10 numbers and skuvar2 = 9 numbers
if file has 35 numbers, then skuvar1= 10, skuvar2= 20, skuvar3= 10 and skuvar4= 5

Can someone help me how to implement it.

Appreciate your help.

Thanks
Chris

Re: Read and Split into Many variables

Posted: Tue Jul 06, 2010 10:52 am
by AbraCadaver
Probably better to use arrays:

Code: Select all

$skus = array_chunk(file('/path/to/sku.txt'), 5);

Re: Read and Split into Many variables

Posted: Tue Jul 06, 2010 10:55 am
by ChrisK
Thank you for the Tip. I will test it out.