无法访问heredoc中的数组

时间:2012-11-25 20:37:32

标签: php heredoc

为什么此代码在我尝试访问$sector_value['sector_info']['purchase_order'];的行上出错?但不是在我打印出变量$sector_counter的第五行?

//SECTOR
$email_body .=  <<<SECTOR_DETAILS
    <tr>
        <td colspan="2">
            Sector $sector_counter;
        </td>
    </tr>

    <tr>
        <td colspan="2">
            Purchase order
        </td>
    </tr>
    <tr>
        <td colspan="2">
        $sector_value['sector_info']['purchase_order'];
        </td>
    </tr>

    <tr>
        <td>
            Proof
        </td>
    </tr>

SECTOR_DETAILS;

这是错误:

  

解析错误:语法错误,意外T_ENCAPSED_AND_WHITESPACE,期待第44行/home/www2isco/public_html/test/bch/queries/submit_order.php中的T_STRING或T_VARIABLE或T_NUM_STRING

谢谢!

1 个答案:

答案 0 :(得分:6)

将变量括在{ .. }中,它位于the docs

//SECTOR
$email_body .=  <<<SECTOR_DETAILS
    <tr>
        <td colspan="2">
            Sector $sector_counter;
        </td>
    </tr>

    <tr>
        <td colspan="2">
            Purchase order
        </td>
    </tr>
    <tr>
        <td colspan="2">
        {$sector_value['sector_info']['purchase_order']}
        </td>
    </tr>

    <tr>
        <td>
            Proof
        </td>
    </tr>

SECTOR_DETAILS;