I am trying to read a CSV file in an array. What is so far away from me to read the CSV in the array:
$ i = 0; While ($ i & lt; $ fileLines) {$ userDB = array (($ i) => array ((title) => $ Harry [$ i] [0], (subtitle) = & gt; $ Harry [$ I] [Hai] [$ i] [1], (Series) => $ Harry [$ i] [2], (author) => $ Harry [$ i] [3] ($ 2) = $ Harry [$ i] [4], (author3) = & gt; $ Harry [$ i] [5], (category) => $ Harry [$ i] [6], (topics) => $ Harry [$ i] [7], (colonumber) => $ Harry [$ i] [8], (ISBN) => $ Harry [$ i ] [9], (publisher) => $ Harry [$ i] [10] (keyword) => $ Harry [$ i] [11], (option1) => $ Harry [$ I] [12], (option2) => $ Harry [$ i] [13], (option3) $ Harry [$ i] [14], (option4) => $ Har [$ I] [15], (option 5) = & gt; $ Harry [$ i] [16], (option 6) = & Gt; $ Harry [$ i] [17]) / End Child array); // end parent array $ i ++; } // end
Here is an example of the CVS I am using:
"Algebra and trigonometry with analytical geometry, classic version" , "Swokowski, Earl", "Cole, Jeffrey A." Trigonometry with Algebra and Analytical Geometry, classic edition 12 SWOKOWSKI, Earl Cole, JEFFERY A. Cengage Teaching, 2009 - 01-28 912 500 +05 9 555717 "All my friends are dead, Cengage Learning, Cengage Learning, "Monsen, Everybody", "John, Jory", Chronicle Books ,,,, 811,874,559 ,,,,, "All my friends have died; MONSEN, Avery John, Jory Chronicle Books 2010-06-30 96 500 + 081187455 9 "All my friends are still dead," "John, Jory", "Monsen, Avery", Chronicle Books ,,,,1452106 9 67 ,,,,, , "All my friends are still dead 2012/03/02 John, Jori Mansen, Every Chronicle Books 2012-03-07 108 500 +1452106 9 67"
My problem comes when I Try to loop through the array for writing. If I comment on the loop of time, then I read the first item in CSV correctly. However, when I try and use the while loop, I do not have any data written for the array. I am totally wrong / what am I doing?
I have not included all my code because I do not want everyone to drown, but if it helps, then I can add more to it.
You must declare your $ userDB
before the loop:
$ i = 0; $ UserDB = array (); While ($ i $ Harry [$ i] [1], (Series) = & gt; $ Harry [$ i] [2], (author) = & gt; $ Harry [$ i] [3], (author2) = & gt; $ Harry [$ i] [4], (author3) = & gt; $ Harry [$ i] [5], (category) = & gt; $ Harry [$ i] [6], (topics) = & gt; $ Harry [$ i] [7], (colporte) = & gt; $ Harry [$ i] [8], (ISBN) = & gt; $ Harry [$ i] [9], (publisher) = & gt; $ Harry [$ i] [10], (keyword) = & gt; $ Harry [$ i] [11], (option1) = & gt; $ Harry [$ i] [12], (Option 2) = & gt; $ Harry [$ i] [13], (option3) = & gt; $ Harry [$ i] [14], (option4) = & gt; $ Harry [$ I] [15], (Option5) = & gt; $ Harry [$ i] [16], (Option 6) = & gt; $ Harry [$ i] [17]) // end hair array); // end parent array $ i ++; } // end
BTW, why do not you use the straightforward or PHP function?
$ userDB = str_getcsv ($ fileLines);
Comments
Post a Comment