Wilda Sagita
Wilda Sagita

Reputation: 123

How to show specific array in foreach

<?php 

$XMLContent=file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"); 

foreach($XMLContent as $line){ 
        if(preg_match("/rate='([[:graph:]]+)'/",$line,$rate)){ 
            echo "$rate[1]<br>"; 
        } 
 } 
?>

but the result are displayed all,my question that displaying data in the first row

Upvotes: 0

Views: 57

Answers (1)

Barmar
Barmar

Reputation: 780769

Use break to stop the loop after the first match:

foreach($XMLContent as $line){ 
    if(preg_match("/rate='([[:graph:]]+)'/",$line,$rate)){ 
        echo "$rate[1]<br>"; 
        break;
    } 
} 

Upvotes: 1

Related Questions