在php中动态填充复选框


populate checkbox dynamically in php

我正在使用PHP中的OAuth API调用获取Gmail联系人,并已成功完成。但是,当我试图在每个电子邮件ID中插入一个复选框时,我遇到了困难。以下是填充电子邮件ID的foreach循环的片段:

$temp = json_decode($xmlresponse, true);
$links = array();
foreach($temp['feed']['entry'] as $cnt) {
    $links[] = $cnt['gd$email']['0']['address'] . "</br>";
}
?>
<span><?php echo implode("'n", $links); ?></span>
<input type="checkbox" name="links[]" value="<?php echo implode("'n", $links); ?> /><br />

它显示电子邮件ID,但此处没有显示复选框。有人能帮我吗?

您需要为每个链接项创建一个复选框输入。

foreach($links as $link){
    //echoes the name of the id
    echo '<span>' . $link . '</span>';
    echo '<input type="checkbox" name="links[]" value="' . $link . '"/>';
}