livewirerules Posted June 13, 2011 Share Posted June 13, 2011 Hi Im trying to load telephone numbers from a csv file and work around the array key values. But when when i try all the key values seems to be Zero. I tried to sort and assing new array key values but still its the same. Below is the code if (($open=fopen("phone.csv","r"))!== FALSE) { while (($data=fgetcsv($open))!==FALSE) { foreach ($data as $key =>$numbr){ /// working code logic echo $key."<br>"; } }} the output is as below 0 0 0 0 0 0 0 can someone please tell me how to assign the keys. Quote Link to comment https://forums.phpfreaks.com/topic/239235-array-keys-are-zero/ Share on other sites More sharing options...
kenrbnsn Posted June 13, 2011 Share Posted June 13, 2011 What does the content of your file look like? Ken Quote Link to comment https://forums.phpfreaks.com/topic/239235-array-keys-are-zero/#findComment-1229077 Share on other sites More sharing options...
livewirerules Posted June 14, 2011 Author Share Posted June 14, 2011 It is a list of phone numbers stored in a new line 578854745 578854845 578854945 578854545 578857545 Quote Link to comment https://forums.phpfreaks.com/topic/239235-array-keys-are-zero/#findComment-1229423 Share on other sites More sharing options...
sasa Posted June 14, 2011 Share Posted June 14, 2011 try if (($data=file("phone.csv", FILE_IGNORE_NEW_LINES))!== FALSE) { //while (($data=fgetcsv($open))!==FALSE) { foreach ($data as $key =>$numbr){ /// working code logic echo $key."<br>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/239235-array-keys-are-zero/#findComment-1229427 Share on other sites More sharing options...
livewirerules Posted June 14, 2011 Author Share Posted June 14, 2011 Thanks... works perfect Quote Link to comment https://forums.phpfreaks.com/topic/239235-array-keys-are-zero/#findComment-1229482 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.