我有一个数组,每个数组都有一个值。如果语句在数组中?
下面是这样一个例子:
$sales_payload = array(
'organization_id' => $organization_id,
'contact_id' => $contact_id,
'status' => 'Open',
'subject' => $_product->post_title." ".str_replace($strToRemove, "", $_POST['billing_myfield12']),
'start_date' => date("Y-m-d"), // set start date on today
'expected_closing_date' => date("Y-m-d",strtotime(date("Y-m-d")."+ 14 days")), // set expected closing date 2 weeks from now
'chance_to_score' => '10%',
'expected_revenue' => 0, //set the expected revenue
'note' => $_POST['order_comments'],
'progress' => array(
'id'=>'salesprogress:200a53bf6d2bbbfe' //fill a valid salesprogress id to set proper sales progress
),
"custom_fields"=> [[
if(strpos($_POST['billing_myfield13'], 'ja') !== false) { [["actief_in_duitsland"=>1]] }
]]
);
现在我试图填补某一阵列在我的代码这一个:
"custom_fields"=> [["actief_in_duitsland"=>1]]
这工作。唯一的事情是我想在某种情况下值是=> 1。 这种情况是如果某个POST请求包含那么某些字符串使价值=> 1
我尝试这样做:
"custom_fields"=> [[
if(strpos($_POST['billing_myfield13'], 'ja') !== false) { [["actief_in_duitsland"=>1]] }
]]
所以
if(strpos($_POST['billing_myfield13'], 'ja') !== false) { [["actief_in_duitsland"=>1]] }
如果$_POST['billing_myfield13']
包含单词“JA”
then [["actief_in_duitsland"=>1]]
不,你不能在数组定义中有'if'语句。但是,你可以使用ternarys,但是否合适是另一回事。 –
或者您可以只分配比较的布尔结果 –