Re: ARRAYS
| From: | Matt McClanahan | Date: | Sun, 29 Oct 2000 22:54:32 +0000 |
| Subject: | Re: ARRAYS | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22578@lists.php.net to get a copy of this message | ||
On Sun, 29 Oct 2000, King Georgie wrote:
> hi!
>
> Can any 1 tell me what the PHP equivaelnt of this PERL code is???
> These lines of PERL input a files contents into an array, compare each value
> in the array to another value, and if they are equal it deletes that array
> entry.
> How do u do that in PHP??
>
> open (DAT,"<$memberinfo/address.txt");
> @database_array = <DAT>;
> close(DAT);
>
> ** foreach $lines(@database_array) { **
> ** chomp($lines); **
$filearray = file("$memberinfo/address.txt");
for ($i = 0; $i < count($filearr); $i++)
$arr[$i] = chop($arr[$i]);
PHP's chop function is essentially the same as Perl's chomp() function.
While PHP does have a foreach control structure, it doesn't work in quite
the same way as Perl's. The PHP foreach structure uses a copy of each
array element. This is why the following code
foreach ($arr as $line)
chop($line);
wouldn't remove the whitespace from the array elements.
Matt