Re: array_diff()?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Actually that was a miss when I was "translating" var names.

Here follows the code again, untouched this time:

<?php
$arquivo1 = 'label_es.ini';
$arquivo2 = 'label_pt.ini';

$fh1 = fopen ($arquivo1,'r');
$fh2 = fopen ($arquivo2,'r');

$array1 = array();
$array2 = array();

while (($linha = fgets($fh1))) {
    $label = explode("=",$linha);
    $array1[] = $label[0];
}

while (($linha = fgets($fh2))) {
  $label = explode("=",$linha);
  $array2[] = $label[0];
}

$labelsFaltantes = array_diff($array1,$array2);

var_dump($labelsFaltantes);
var_dump($array1);
var_dump($array2);
?>

File _pt has ~2300 lines while file _es has ~1700. Not a chance of them
having the same labels :)

On Wed, Jun 25, 2008 at 5:18 PM, Boyd, Todd M. <tmboyd1@xxxxxxxx> wrote:

> > -----Original Message-----
> > From: Thiago H. Pojda [mailto:thiago.pojda@xxxxxxxxx]
> > Sent: Wednesday, June 25, 2008 3:10 PM
> > To: php-general@xxxxxxxxxxxxx
> > Subject:  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
>



-- 
Thiago Henrique Pojda

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux