首页 > 解决方案 > 如何在同一个 php 方程中更改参数的值

问题描述

我正在尝试更改每个“column_id”参数的“文本”参数的值。例如:

'column_id' => 'email'
'text' => 'foresthill@mailto.com

'column_id => 'phone'
'text' => '555-555-5555'

如果我有一个 column_id 和 text 参数,则该等式有效,但是当我尝试将第二个 column_id 'phone' 的值更改为 text 值 555-555-5555 时,电话号码会显示在“email”列中。

如何使文本值进入其自己的 column_id,如下所示:

email = example@example.com
phone = 555-555-5555.

代码:

//********************** Update Pulse Columns for a specific pulse ***********************      
$put_fields = array(
     //monday.com board and user id values
     'board_id' => '194618490',
     'column_id' => 'email1',
     'pulse_id' => 197299328,
     'text' => 'foresthill@mailto.com'
);    
$put_fields = array(
     //monday.com board and user id values
     'board_id' => '194618490',
     'column_id' => 'phone',
     'pulse_id' => 197299328,
     'text' => '555-555-5555'
);
$ch =  curl_init('https://api.monday.com:443/194618490/columns/email1/text.json?api_key=api_key');
//curl_setopt($ch, CURLOPT_USERAGENT, 'ARPR');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
//curl_setopt($ch, CURLOPT_URL, URL. $api);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $put_fields);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
//$curl_result = curl_exec($ch);
//curl_close($ch);
print "<pre>";
print_r($curl_result);
print "</pre>";

标签: phpparameters

解决方案


根据monday.com doc,该 api 将仅更新一列。URL 包含列名。听起来您需要两个单独的电话。


第二个$put_fields= 覆盖第一个的内容$put_fields=。所以当它到达 curl 的时候,没有 'column_id' => 'email.

一种方法可能是:使column_id本身成为一个数组,例如

column_id => ['email' : theemail, 'phone': 5555555]

显然,这需要对curl_setopt($ch, CURLOPT_POSTFIELDS, $put_fields);.

$put_fields另一种选择,在数组中单独列出键。目前尚不清楚您为什么需要column_id它,因为它没有被使用。


推荐阅读