note 102681 modified in function.in-array by danbrown

From: Date: Mon, 28 Feb 2011 17:55:27 +0000
Subject: note 102681 modified in function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177413@lists.php.net to get a copy of this message
strange behaviour of in_array: If you have an array like: <?php $a = array(0,1,2,3,4,5); in_array("bla", $a) returns true in_array("bla6", $a) returns true in_array("6bla", $a) returns false ?> If you have an array like (without 0): <?php $a = array(1,2,3,4,5); in_array("bla", $a) returns false in_array("6bla", $a) returns false in_array("5bla", $a) returns true ?> so better use strict arg! --was-- strange behaviour of in_array: If you have an array like: $a = array(0,1,2,3,4,5); in_array("bla", $a) returns true in_array("bla6", $a) returns true in_array("6bla", $a) returns false If you have an array like (without 0): $a = array(1,2,3,4,5); in_array("bla", $a) returns false in_array("6bla", $a) returns false in_array("5bla", $a) returns true so better use strict arg! http://php.net/manual/en/function.in-array.php

« previous php.notes (#177413) next »