我在這段代碼的末尾想要的是一個數組,它不斷添加給一個數組中的所有$ id。添加到循環結尾的數組
當前代碼在數組中執行15,然後被接下來的15個項目覆蓋。我想能夠在數組中有30個項目的代碼末尾有一個數組。
我下面的代碼:
$idArray = array();
do {
$html = file_get_html($url);
parseItems($html, $dbh);
sleep_flush($chunks=1); // ADJUST LATER
}
while (!empty($html->find('span[class=load-more-message]', 0)));
$html->clear();
unset($html);
// -------------------------------------------------
function parseItems($html, $dbh) {
foreach($html->find('div.product-stamp-inner') as $content) {
$detail['itemid'] = filter_var($content->find('a.product-title-link', 0)->href, FILTER_SANITIZE_NUMBER_FLOAT);
$id = $detail['itemid'];
$idArray[] = $id; //Counting and adding items to an array
$detail['title'] = $content->find('span.title', 0)->plaintext;
$description = $detail['title'];
if (!tableExists($dbh, $id, $detail)) {
echo $id . " > " . $description . "> Table does not exist >";
createTable($dbh, $id, $description);
insertData($dbh, $id, $detail);
echo "<br>";
} else {
echo $id . " > " . $description . "> Table already exists >";
checkData($dbh, $id, $detail);
echo "<br>";
}
}
print_r($idArray);
}
從函數定義中拉出'$ idArray'使其成爲全局/會話v良莠不齊。 –