I have an array each array has a value.
Here is an example of this:
$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]] } ]] ); I am now trying to fill a certain array in my code this one:
"custom_fields"=> [["actief_in_duitsland"=>1]] This works. Only thing is I want the value to be =>1 on a certain condition. This condition is if a certain POST request contains a certain string then make the value => 1
I tried this :
"custom_fields"=> [[ if(strpos($_POST['billing_myfield13'], 'ja') !== false) { [["actief_in_duitsland"=>1]] } ]] So
if(strpos($_POST['billing_myfield13'], 'ja') !== false) { [["actief_in_duitsland"=>1]] } If the $_POST['billing_myfield13'] contains the word 'ja'
then [["actief_in_duitsland"=>1]]
ifstatements inside array definitions. You can however use ternarys, though whether those are appropriate is another matter.