note 16883 modified in function.array-search by zak

From: Date: Sat, 17 Nov 2001 06:59:21 +0000
Subject: note 16883 modified in function.array-search by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20945@lists.php.net to get a copy of this message
NOTE!! When using "file" to load the contents of a file into an array newlines "\n" are inclued on each line of the array. The newlines cause functions like array_search to appear to fail as the newline is somewhat hidden. Use something like this to do a cleanup before using array_search or in_array: foreach (file ('test.txt') as $line) { $array[] = substr ($line, 0, -1); } --was-- NOTE!! When using "file" to load the contents of a file into an array newlines "\n" are inclued on each line of the array. The newlines cause functions like array_search to appear to fail as the newline is somewhat hidden. Use something like this to do a cleanup before using array_search or in_array: for ($temp = 0; $temp < count($formatTemplate); $temp++) { $formatTemplate[$temp] = ereg_replace ("\n", "", $formatTemplate[$temp]); } http://www.php.net/manual/en/function.array-search.php

« previous php.notes (#20945) next »