RE: [PHP] array_diff()?
| From: | Boyd, Todd M. | Date: | Wed, 25 Jun 2008 20:18:42 +0000 |
| Subject: | RE: [PHP] array_diff()? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275954@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Thiago H. Pojda [mailto:thiago.pojda@gmail.com]
> Sent: Wednesday, June 25, 2008 3:10 PM
> To: php-general@lists.php.net
> Subject: [PHP] array_diff()?
>
> *accidentally sent*
>
> Guys,
>
> Perhaps I'm missing something or just trying with the wrong tools...
>
> But the thing is, I have two arrays and want to know what values are
in
> one
> that aren't in the other.
>
> They're very long arrays (label files for translation) and the
> array_diff()
> is returning null, even if I force a difference.
>
> What's up?
>
> <?php
> $file1 = 'label_es.ini';
> $file2 = 'label_pt.ini';
>
> $fh1 = fopen ($file1,'r');
> $fh2 = fopen ($file2,'r');
>
> $file1 = array();
> $file2 = array();
>
> while (($line = fgets($fh1))) {
> $label = explode("=",$line);
> $array1[] = $label[0];
> }
>
> while (($line = fgets($fh2))) {
> $label = explode("=",$line);
> $array2[] = $label[0];
> }
>
>
> $missingLabels= array_diff($array1,$array2);
>
>
> var_dump($labelsFaltantes); // returns nothing
> var_dump($array1); // returns a lot of stuff
> var_dump($array2); // returns a lot of stuff
> ?>
Umm...
Is $missingLabels supposed to be what you're var_dump()ing later in the
code? Cuz you call it $labelsFaltantes almost immediately after, which
has not been defined (by what I can see).
Todd Boyd
Web Programmer