dimanche 5 avril 2020

Get value into if statement (PHP)

I have two IF statements, how can i get value from first into the other one? Next i want to do an insert query to database.

if (!is_null($elements)) {
    foreach ($elements as $element) {
        $nodes = $element->childNodes;
        foreach ($nodes as $node) {
            $eq_l = preg_replace("/[0-9]/", "-", $node->nodeValue);
            $eq_l = explode('-',$eq_l);
            $e_home = $eq_l[0];
            $e_away = $eq_l[2];
        }
    }
}

$elements = $xpath->query("//*[@id='bq_plantilla']");

if (!is_null($elements)) {
    foreach ($elements as $element) {
        $nodes = $element->childNodes;
        foreach ($nodes as $node) {
            $boxes= explode('BANQUILLO',$node->nodeValue);
            $exploded = preg_split('/[\d-\s]\d\s/', $boxes[0]); 
            foreach($exploded as $index => $answer){
                if (!empty($answer) && $index >0 && $index <12){
                    $quit = array("Goal", "YC", "'", "SUBS", "(D.P.)");
                    $quit = str_replace($quitar, "", $answer);
                    $quit = str_replace(":", "*", $quit);
                    $local = preg_replace("/[0-9]{2}/", "", $quit);
                    if (substr_count($local,"*")>0){
                        $loc_camb = explode('*',$local);
                        $local = $loc_camb[0];
                    }
                echo "$local<br>";
                echo "$e_home<br>";
                echo "$e_away<br>";
                }  
            } 
        }
    }
}

$e_home and $e_away no returns values.

Thanks!

Aucun commentaire:

Enregistrer un commentaire