如果设置了PHP,则插入值

时间:2015-04-30 16:49:58

标签: php arrays parsing

寻找一些指导,因为我不知道如何将我的所有设置选项回显到specification under container-types请求中。所以我有一个用户提交表格的数组:

Array
(
[_wpcf7] => 5
[_wpcf7_version] => 4.1.2
[_wpcf7_locale] => en_US
[_wpcf7_unit_tag] => wpcf7-f5-o1
[_wpnonce] => 1531937d4e
[your-name] => TEST
[your-email] => test@test.com
[title] => test
[Description] => test
[venues] => Dragonfly
[duedate] => 2015-04-11
[options] => Array
    (
        [0] => Print Business Card (3.5x2)
        [1] => Google Ads Package
        [2] => Print Ticket (1.5x5.5)
        [3] => Print Magazine Ad (8x10.75)
    )

[_wpcf7_is_ajax_call] => 1
[upload] => ditch_fridays_logo.png
)

从那里我解析数组以获取变量:

$submittedBy = $posted_data['your-name'];
$eMail = $posted_data['your-email'];
$projectTitle = $posted_data['title'];
$projectDescription = $posted_data['Description'];
$venue = $posted_data['venues'];
$deadline = $posted_data['duedate'];
$options = $posted_data['options'];
$upload = $posted_data['upload'];

然后我创建了体式任务

// First we create the task
$result = $asana->createTask(array(
    'workspace' => $workspaceId, // Workspace ID
    'name' => $projectTitle, // Name of task
    'assignee' => 'somewhere@somewhere.com', // Assign task to...
    'due_on' => $deadline,
    'notes' => 'Submitted By: ' . $submittedBy . "\n" . 'E-Mail: ' . $eMail . "\n\n" . '--------------------------------------------------' . "\n\n" . 'Task Name: ' . $projectTitle . "\n\n" . 'Description:  ' . $projectDescription . "\n\n" . 'Venue:  ' . $venue . "\n\n" . 'Deadline: ' . $deadline . "\n\n" . 'Attachments: http://inkentertainment.com/graphics/saved/' . $upload 
));

问题是,我无法在任务创建的备注部分中包含所选选项。只有当用户选择了所有选项($ posted_data ['选项'])时,我才会如何处理? (在表单上有一个大约10的列表,但用户将选择2或3)

我希望我已经足够清楚了解你,如果不让我知道,我会尽力澄清

1 个答案:

答案 0 :(得分:0)

$options = ( isset   ( $posted_data[ 'options' ] ) &&
             is_array( $posted_data[ 'options' ] ) ) ?
           $posted_data[ 'options' ] : array();

这里你将拥有一个零或多个元素的数组。

如果您需要字符串,则可以使用implode

http://php.net/manual/en/function.implode.php

ex:$options = implode( ', ', $options );