atl_andy Posted April 1, 2008 Share Posted April 1, 2008 Why does the output of the following simple array append a 1 at the end of any names or emails entered? It doesn't matter how many items I put in the array, they all add a 1 at the end. I have had it up to 10 names and emails. $contact = array( array('email'=>$_GET['email1'],'name'=>$_GET['name1']), array('email'=>$_GET['email2'],'name'=>$_GET['name2'])); for ($i=0;$i<count($contact);$i++) { $next = $contact[$i]; echo "<pre>"; echo print_r($next['name']); echo "</pre>"; Output will be: John1 Allen1 Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/ Share on other sites More sharing options...
papaface Posted April 1, 2008 Share Posted April 1, 2008 I think it is because $next is multidimensional. Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506704 Share on other sites More sharing options...
atl_andy Posted April 1, 2008 Author Share Posted April 1, 2008 How to remove? Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506708 Share on other sites More sharing options...
papaface Posted April 1, 2008 Share Posted April 1, 2008 Try: for ($i=0;$i<count($contact);$i++) { $next = $contact[$i]; echo "<pre>"; echo $next['name']; echo "</pre>"; } You don't echo print_r an array. The echo was producing the number 1. Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506710 Share on other sites More sharing options...
atl_andy Posted April 1, 2008 Author Share Posted April 1, 2008 It was a typo that I left the } off the for loop. Other than that, your code looks the same as mine.... Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506713 Share on other sites More sharing options...
atl_andy Posted April 1, 2008 Author Share Posted April 1, 2008 nm.... Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506715 Share on other sites More sharing options...
atl_andy Posted April 1, 2008 Author Share Posted April 1, 2008 That did it. Thanks. Link to comment https://forums.phpfreaks.com/topic/99030-simple-array-question/#findComment-506716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.