Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

James Barrett
13,253 PointsWhy does the array return the same value twice?
array(1) { [0]=> array(16) { ["U_ID"]=> string(1) "1" [0]=> string(1) "1" ["U_Forename"]=> string(5) "James" [1]=> string(5) "James" ["U_Surname"]=> string(7) "Barrett" [2]=> string(7) "Barrett" ["U_Email"]=> string(25) "james-barrett@hotmail.com" [3]=> string(25) "james-barrett@hotmail.com" ["U_Password"]=> string(8) "password" [4]=> string(8) "password" ["U_Team"]=> string(7) "Arsenal" [5]=> string(7) "Arsenal" ["U_Biography"]=> string(19) "Hi there I am James" [6]=> string(19) "Hi there I am James" ["U_Activated"]=> string(1) "1" [7]=> string(1) "1" } }
I am working on my own project and the fetchAll() returns an array of the result. However why is it two-dimensional and why is it returning the same value twice?
Thanks, James.
1 Answer
Henrik Hansen
23,176 PointsBecause fetchAll() returns both the associated array (column names as key) as well as the numerical array. You can set the fetch mode as an argument: PDO fetchAll
Or you can use the regular fetch() witch returns one row at a time, and loop it to get all the rows from your query.
James Barrett
13,253 PointsJames Barrett
13,253 PointsApologies for formatting of the code... I did indent it however it did not do it correctly :S