在两个循环内设置数组

I am posting a text area to my php script where I then do a loop for each line of the text area and then using the data from the text area loop another time. I am then trying to set an array for each one and at the end retrieve an array for all of them. However my code is giving me errors:

if (isset($_POST['submit'])) {
        $entries = array();
    $text    = trim($_POST['facebookpage']);
    $text    = explode("
", $text);
    foreach ($text as $line) {
        $data = $html2->find("table.profileInfoTable");
        $text2 = trim($data[0]);
        $text2 = explode("<tr>", $text2);
        foreach ($text2 as $line) {
            if (strpos($line, 'Location') !== false) {
                $location = $line;
            }
        }
        $data1 = $html2->find("table.profileInfoTable");
        $text2 = trim($data1[0]);
        $text2 = explode("<tr>", $text2);
        foreach ($text2 as $line) {
            if (strpos($line, 'Email') !== false) {
                $email = $line;
            }
        }
    $mainarray = array("Email" => $email, "Location" => $location);
    array_push(($mainarray),$entries);
    }
    var_dump($entries);
}`

Also the error is:

Fatal error: Only variables can be passed by reference in /home2/statonme/public_html/scraper.php on line 61

Usually, the error messages of PHP give you a very good idea of what's wrong with your script.

I don't know where 'Line 61' in your script is, but I believe that if you put anything into brackets, it is considered an 'equation'...meaning that ($main_array) is not a variable...and you can't change an equation. You can only change variables.

Try removing the brackets around $main_array in array_push(($mainarray),$entries); (making it: array_push($mainarray, $entries);) and come back with results please.

I think you have the arguments to array_push backwards. The array you're adding to should be the first argument, the rest of the arguments are the elements being added. So it should be:

array_push($entries, $mainarray);

Or, more simply:

$entries[] = array("Email" => $email, "Location" => $location);