php: mysql sonuç kümesi simüle

1 Cevap

Ben bir dizinde TextFiles değerleri çekmek ve dizilerin içine değerlerin bu listeleri koymak istiyorum.

Ben nesne "gibi" mysql sonucu setine bu dizileri düzenlemek ancak nasıl emin değilim.

İşte ben bugüne kadar ne var:

// Retrieve all files names, create an array
$dir    = './textfiles/';
$files1 = glob($dir . '*' . '.txt');

foreach ($files1 as $filename) 
{
    $file_array[] = basename($filename);
}

//use the file function to create arrays from the text files
$filepath = $dir . $file_array[0];
$text_array = file($filepath);

The code above only retrieves the information from 1 text file. How can I retrieve the other values into additional arrays?
Secondly once all the arrays are retrieved, how can a make the object?
Thirdly, how can I make this a function to accomodate newly created textfiles?

1 Cevap

Öncelikle yazdı

$filepath = $dir.$file_array[0];
$text_array = file($filepath);

Bu kod parçası sadece ilk dosyadan dizi oluşturun

Sen dizi döngü gerekir. Basitçe:

// Retrieve all files names, create an array
$dir    = './textfiles/';
$files1 = glob($dir . '*' . '.txt');

$arr_of_objects = array();

foreach ($files1 as $filename) 
{
    $arr = file($filename);
    $arr_of_objects[] = (object)$arr;
}

(Nesne) döküm Eğer nesne dizisi dönüştürmek için yardımcı olacaktır.