2016-12-09 103 views
-2

在這裏,我想只顯示數學馬克顯示只有數學的價值,我不知道該怎麼辦,我想,但我不能夠顯示: -如何在這段代碼

<?php 
 
$marks1=array(
 
\t array("Maths"=>80,"Physics"=>89,"Chemistry"=>79), 
 
\t array("Maths"=>90,"Physics"=>78,"Chemistry"=>87), 
 
\t array("Maths"=>78,"Physics"=>90,"Chemistry"=>79) 
 
); 
 
echo "<ul>"; 
 
for($r=0;$r<count($marks1);$r++) 
 
{ 
 
\t echo "<li>"; 
 
\t foreach($marks1[$r] as $key=>$value) 
 
\t { 
 
\t \t echo $key." = ".$value." "; 
 
\t } 
 
\t echo "</li>"; 
 
\t echo "<br><br>"; 
 
} 
 
echo "</ul>"; 
 

 
?>

+0

'$ marks1 [$ r] ['Maths']'。努力,閱讀PHP手冊。 –

+0

'if(key =='Maths'){echo $ key。「=」。$ value。「」;}' –

+0

哦,現在已經知道了,如果(key =='Maths')你錯過了$ –

回答

1

請只使用foreach()。並避免類似的事情等echo "<ul>" ....按照下面的編碼格式...

<?php 
    $marks1 = array(
    array("Maths" => 80, "Physics" => 89, "Chemistry" => 79), 
    array("Maths" => 90, "Physics" => 78, "Chemistry" => 87), 
    array("Maths" => 78, "Physics" => 90, "Chemistry" => 79) 
); 
?> 

<ul> 
    <?php foreach($marks1 as $marks) { ?> 
    <li> 
     Maths = <?php echo $marks['Maths']; ?> 
    </li> 
    <?php } ?> 
</ul> 
1

我希望它做的所謂

<?php 
$marks1=array(
    array("Maths"=>80,"Physics"=>89,"Chemistry"=>79), 
    array("Maths"=>90,"Physics"=>78,"Chemistry"=>87), 
    array("Maths"=>78,"Physics"=>90,"Chemistry"=>79) 
); 

foreach($marks1 as $mark){ 

    echo "MATH = ".$mark['Maths']."<br>"; 
} 

?> 

輸出的最短途徑:

MATH = 80 
MATH = 90 
MATH = 78