Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
How to use array_diff for (.txt) files in PHP
<?php
$new = array("12", "11", "10", "9", "8", "7", "6", "5", "4");
$old = array("10", "9", "8", "7", "6", "5", "4", "3", "2", "1");

$result = array_diff($new, $old);

print_r($result);
?>

The result is Array ( [0] => 12 [1] => 11 ) so 12 and 11

According to this example how to use array_diff for (.txt) files in PHP?

Here are (.txt) examples:

New (.txt) file

Something here12
Something here11
Something here10
Something here9
Something here8
Something here7
Something here6
Something here5
Something here4
Something here3

Old (.txt) file

Something here10
Something here9
Something here8
Something here7
Something here6
Something here5
Something here4
Something here3
Something here2
Something here1

Output (.txt) file

Something here12
Something here11
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You just need to reproduce your arrays from the text files :

<?php
$new = explode(PHP_EOL, file_get_contents('new.txt').PHP_EOL);
$old = explode(PHP_EOL, file_get_contents('old.txt').PHP_EOL);
$result = array_diff($new, $old);

$output= fopen("Output.txt", "w") or die("Unable to open file!");
foreach($result as $value){
    fwrite($output, $value.PHP_EOL);
}

?>

I am not sure if you wanted the strip the "Something here" but in your exemple output.txt it seems like not.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda