Jump to content

Help with in_array() and chr()


thepip3r

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/30900-help-with-in_array-and-chr/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.