循环遍历数组时返回奇怪的值

Emm*_*myS 2 php arrays foreach

$rows = getChallengeList();
error_log(print_r($rows, 1));
?>
<table border="1">
    <tr><th>ID</th><th>Title</th><th>Description</th></tr>
    <?php foreach ($rows as $row): ?>
        <?php foreach($row as $chal): ?>
        <tr>
            <td><?= $chal['loyalty_challenges_id']; ?></td>
            <td><?= $chal['title']; ?></td>
            <td><?= $chal['description']; ?></td>
        </tr>    
        <?php endforeach; ?>
    <?php endforeach; ?>
</table>
Run Code Online (Sandbox Code Playgroud)

error_log返回:

[11-Jan-2013 10:44:27] Array
(
    [0] => Array
        (
            [loyalty_challenges_id] => 1
            [title] => New Customer Special
            [description] => Reward new customers with a free order of breadsticks after placing their second order during their first 30 days 
        )

    [1] => Array
        (
            [loyalty_challenges_id] => 2
            [title] => Frequent Flyer Special
            [description] => Reward long-time customers who order often with a free pizza
        )

)
Run Code Online (Sandbox Code Playgroud)

但是循环呈现的值如下所示:

<table border="1">
    <tr><th>ID</th><th>Title</th><th>Description</th></tr>
    <tr>
        <td>1</td>
        <td>1</td>
        <td>1</td>
    </tr>    
    <tr>
        <td>N</td>
        <td>N</td>
        <td>N</td>
    </tr>    
    <tr>
        <td>R</td>
        <td>R</td>
        <td>R</td>
    </tr>    
    <tr>
        <td>2</td>
        <td>2</td>
        <td>2</td>
    </tr>    
    <tr>
        <td>F</td>
        <td>F</td>
        <td>F</td>
    </tr>    
    <tr>
        <td>R</td>
        <td>R</td>
        <td>R</td>
    </tr>    
</table>
Run Code Online (Sandbox Code Playgroud)

知道会导致什么?自从我使用直接php以来,已经有一段时间了,而不是拥有自己的数组处理功能的CMS.

mpa*_*per 5

你有一个循环太多:

$rows = getChallengeList();
error_log(print_r($rows, 1));
?>
<table border="1">
    <tr><th>ID</th><th>Title</th><th>Description</th></tr>
    <?php foreach ($rows as $chal): ?>
        <tr>
            <td><?= $chal['loyalty_challenges_id']; ?></td>
            <td><?= $chal['title']; ?></td>
            <td><?= $chal['description']; ?></td>
        </tr>    
    <?php endforeach; ?>
</table>
Run Code Online (Sandbox Code Playgroud)