Replace a yield in php 5.3.3

-1

Hello what happens is that the server I work with is the version of php 5.3.3 and because for bigger issues we can not simply update the php, and the code that I use to perform an insertion in the database uses the function yield and only available from 5.5, how can I replace it?

function filedata(){
$central = 'AVC05';
    $file = fopen("data_centrales/datos_".$central.".log", "r");
    if(!$file){
        echo "No se pudo abrir el archivo";
    } else {
        while(($line = fgets($file)) !== false){
            yield $line;
        }
    }
}
    
asked by Shack 06.11.2018 в 14:33
source

1 answer

1

You just have to store the values in an array and then return that array.

function filedata(){
    $central = 'AVC05';   
    $fi le = fopen("data_centrales/datos_".$central.".log", "r");
    if(!$file){
        echo "No se pudo abrir el archivo";
    } else {
        $lines = [];
        while(($line = fgets($file)) !== false){
            $lines[] = $line;
        }
        return $lines
    }
}
    
answered by 06.11.2018 / 14:45
source