dsfykqq3403 2012-09-18 14:22
浏览 8
已采纳

从数组中获取数据以用于电子邮件

I have the following example of a series of checkboxes on a form:

<?php

echo $this->Form->input(
    'reason', array(
        'label'=>false,
        'type' => 'select', 
        'multiple' => 'checkbox',
        'options' => array(
            'Contact me' => 'Contact me',
            'Brochure request' => 'Brochure request',
            'Demonstration request' => 'Demonstration request',
            'Training' => 'Training',
            'Support' => 'Support',
            'Other' => 'Other'
        )
    ));

?>

This is then set as a variable in the controller like:

$this->set('reason', $this->data['Contact']['reason']);

And then in the email template I have tried doing this:

<?php var_dump( implode( ', ', $reason ) ); ?>

Which gives a result like: string(28) "Contact me, Brochure request" How do I remove those quotation marks and the string(28) prefix?

What's the best way of doing this? Thanks

  • 写回答

2条回答 默认 最新

  • duanmu2013 2012-09-18 14:53
    关注

    use the string helper/text helper. It has a built in toList function.

    // controller
    App::uses('String', 'Utility');
    echo String::toList($this->request->data['Contact']['reason']);
    
    // or
    // controller
    $this->set('reason', $this->data['Contact']['reason']);
    // view
    echo $this->Text->toList($reason);
    // outputs 1, 2, 3 and 4
    

    assuming reason is an array in the format:

    array(
        (int) 0 => '1',
        (int) 1 => '2',
        (int) 2 => '3',
        (int) 3 => '4'
    )
    

    or just do a simple foreach($reason as $k => $v) { echo $v; }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大