thepip3r Posted December 16, 2006 Share Posted December 16, 2006 I have an array $chars that has some of the 256 characters but not all in it (ie abc,ABC,123,!@#, and some of the upper ASCII characters as well) when I try to do an evaluation using in_array(), it always evaluates to true and I can't seem to figure out why; can anyone offer any pointers?[code]echo "<table width=\"100%\"><tr>";for ($i=1; $i<256; $i++) { if (in_array(chr($i), $chars)) { if ($i % 10 == 0) { echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td></tr><tr>"; } else { echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td>"; } } else { if ($i % 10 == 0) { echo "<td>2 $i: " . chr($i) . "<br /></td></tr><tr>"; } else { echo "<td>2 $i: " . chr($i) . "<br /></td>"; } }}echo "</tr></table>";[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 16, 2006 Share Posted December 16, 2006 Both of your sub-if statements are the same:[code]if ($i % 10 == 0) { echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td></tr><tr>";[/code][code]if ($i % 10 == 0) { echo "<td>2 $i: " . chr($i) . "<br /></td></tr><tr>";[/code] Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 16, 2006 Author Share Posted December 16, 2006 no they're not. the second sub-if entries are prefaced with a number 2 and also, the chr($i) is not encapsulated in bold tags -- those two indicators are how I know that it's always evaluating to true. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 17, 2006 Share Posted December 17, 2006 Can you show us a dump of the array $chars? It is unclear exactly what you are trying to do.Ken Quote Link to comment Share on other sites More sharing options...
thepip3r Posted December 17, 2006 Author Share Posted December 17, 2006 what don't you understand?? my array chars looks something like:[code]$chars[] = "a";$chars[] = "b";$chars[] = "A";$chars[] = "B";$chars[] = "!";$chars[] = "@";$chars[] = chr(192);$chars[] = chr(215);echo "<table width=\"100%\"><tr>";for ($i=1; $i<256; $i++) { if (in_array(chr($i), $chars)) { if ($i % 10 == 0) { echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td></tr><tr>"; } else { echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td>"; } } else { if ($i % 10 == 0) { echo "<td>2 $i: " . chr($i) . "<br /></td></tr><tr>"; } else { echo "<td>2 $i: " . chr($i) . "<br /></td>"; } }}echo "</tr></table>";[/code]..so I'm looping thorugh 255 out of the 256 chars possible (1-255 (excluding 0 which is null)) to see if they exist in my array. If they do, it's supposed to enbolden those chars. If it doesn't, it supposed to format them normally. Hence the bold tags in the first set of sub-ifs and the non-inclusion of the bold tags in the second sub-if. Quote Link to comment Share on other sites More sharing options...
Azu Posted December 17, 2006 Share Posted December 17, 2006 Maybe use something like[code]$chars[0] = "a";$chars[1] = "b";$chars[2] = "A";$chars[3] = "B";$chars[4] = "!";$chars[5] = "@";$chars[6] = chr(192);$chars[7] = chr(215);[/code]instead? 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.