kproctor Posted March 14, 2017 Share Posted March 14, 2017 Hi, The below foreach loop is adding characters to the results that should not be there. Any idea why this is happening and how I can fix it. It's returning these results B 4.3900 The B should not be there. ------------------------------------- Here is where the results are being pulled from [37] => Array([name] => FI Name[types] => Array([0] => FI Name[1] => 2.7000[2] => 3.1400[3] => 3.1400[4] => 3.0400[5] => 3.6500[6] => 4.3900[7] => 4.6400) foreach($selected_lender as $item) { echo"<br>"; echo $item[6]; echo"<br>"; //echo $item } Quote Link to comment Share on other sites More sharing options...
requinix Posted March 14, 2017 Share Posted March 14, 2017 There is no 'B' anywhere in that part of the array so it is coming from somewhere else. Probably the array entry before the one you've shown. What does $selected_lender[36] look like? Quote Link to comment Share on other sites More sharing options...
kproctor Posted March 14, 2017 Author Share Posted March 14, 2017 Weird, when I assign the result to a variable and echo it outside the foreach statement the extra character is removed. Does anyone know why this happens? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 14, 2017 Share Posted March 14, 2017 My guess is that 'B' is the char in position 6 of a string. But without more code and data that remains a guess. Quote Link to comment Share on other sites More sharing options...
gizmola Posted March 15, 2017 Share Posted March 15, 2017 Ok, but let's look at what you are actually after here. My best guess: foreach($selected_lender as $item) { echo"<br>"; echo $item['types'][6]; echo"<br>"; //echo $item } This is how you would reference an array element of a nested array without otherwise nesting another foreach loop. Quote Link to comment 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.