Why in_array doesn't work on array that was created using loop in PHP? -
why in_array not work on array create loop php ?
this below code show match found.
<?php ($i = 0; $i < 10; ++$i) { $people[] = $i; } if (in_array('test', $people)) { echo "match found"; } else { echo "match not found"; } ?> and below code show match not found.
<?php $people = array("0","1","2","3","4","5","6","7","8","9"); if (in_array('test', $people)) { echo "match found"; } else { echo "match not found"; } ?> how solve first code show match not found
you change
$people[] = $i; ---by--> $people[] = "$i"; then compare strings
<?php ($i = 0; $i < 10; ++$i) { $people[] = "$i"; } if (in_array('test', $people)) { echo "match found"; } else { echo "match not found"; } ?>
Comments
Post a Comment