php简单的html dom返回数组?

I'm trying to create an app using the simple HTML DOM php script, but im running into a wall currently with it - hope you can help.

The aim is to read product numbers from mySQL database, concat these numbers with a url constant and then parse this resulting website for a specific class. The result should then be printed to the screen.

My problem is that the script is returning only the first result from the function array, i have tried a few things, such as trying to call $prices->children[4], but nothing seems to help.

When i trigger the function get_prices_array() with a url, it brings back multiple results -> but when i return this inside my while loop it only brings back the first result in the array.

Heres my code, hope you can point me in the right direction!

Thanks!

<?php

include('simple_html_dom.php');

function get_prices_array($url) {

    $x = file_get_html($url);
    foreach ($x->find('span.price')as $dom) {
        $y = $dom->outertext;
        return $y;
    }
    $x->clear();
}

$con = mysqli_connect("localhost", "***", "***", "***");
// Check connection
if (mysqli_connect_errno()) {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

$result = mysqli_query($con, "SELECT * FROM articles");

while ($row = mysqli_fetch_array($result)) {
    $constant = '***';
    $prices = get_prices_array($constant . $row["product_number"]);
    echo $row["product_number"] . " - " . $prices . '<br />';
}

mysqli_close($con);
?>

// EDIT //

I changed the function get_prices_array() to loop through each span price class and add the result to an array, the array is then returned from the function. The first 5 results from the array are then stored to variables and added to the return string. Thanks for your help!

<?php

include('simple_html_dom.php');

function get_prices_array($url) {

$x = file_get_html($url);
$y = array();
foreach ($x->find('span.price')as $dom) {
    $x = ($dom->outertext);
    $y[] = $x;
}
return $y;
//$x->clear();
}

$con = mysqli_connect("localhost", "***", "***", "***");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

$result = mysqli_query($con, "SELECT * FROM articles");

while ($row = mysqli_fetch_array($result)) {
$constant = '***';
$prices = get_prices_array($constant . $row["product_number"]);
$pos1 = $prices[0];
$pos2 = $prices[1];
$pos3 = $prices[2];
$pos4 = $prices[3];
$pos5 = $prices[4];
echo $row["product_number"] . " - " . $pos1 . " - " . $pos2 . " - " . $pos3 . " - " .   $pos4 . " - " . $pos5 .'<br />';
}

mysqli_close($con);
?>

I think problem is because of return used in foreach loop of function get_prices_array($url).

it is executing foreach loop only once. There is no meaning of loop if you are returning without condition inside loop.