鍍金池/ 問答/PHP  Linux  網(wǎng)絡(luò)安全  HTML/ php curl ,如何給 undefined 代替 null?

php curl ,如何給 undefined 代替 null?

當(dāng)我 curl 請(qǐng)求給對(duì)方時(shí)

$data = array(
    "a" => $a,
    "b" => $b
  );
  $data_string = json_encode($data);

假設(shè)我這邊給對(duì)方的 b 沒有值
對(duì)方那邊收到會(huì)是null
那是否可以變成
當(dāng)我這邊沒有值的時(shí)候
我可否主動(dòng)給對(duì)方 undefined 而不是 null?

對(duì)方是這樣設(shè)定的:
clipboard.png

回答
編輯回答
柒喵

看b的值是什么類型,如果b沒有值,那就用這個(gè)類型的默認(rèn)值,但是b字段在是存在的,保證結(jié)構(gòu)體是一致的,而不是變來變?nèi)ァ?/p>

2017年9月5日 01:21
編輯回答
青黛色
$data = array(
    "a" => $a,
  );
if($b)
{
    $data['b'] = $b;
}
2018年4月3日 09:28