我想将值从 API 传递到数组,但我无法弄清楚我需要编写什么代码。 当前它返回 [1481367,7546218] 如何在数组中传递它
$content = array($result) ;
以下是 API 代码
$Login = 8632465; #Must be Changed
$apiPassword = "Kcfve123*"; #Must be Changed
$data = array("Login" => $Login, "Password" => $apiPassword);
$data_string = json_encode($data);
$ch = curl_init('http://client-api.instaforex.com/api/Authentication/RequestPartnerApiToken');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
$token = curl_exec($ch);
curl_close($ch);
$apiMethodUrl = 'partner/GetReferralAccounts/'; #possibly Must be Changed
$parameters = $Login; #possibly Must be Changed. Depends on the method param
$ch = curl_init('http://client-api.instaforex.com/'.$apiMethodUrl.$parameters);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); # Turn it ON to get result to the variable
curl_setopt($ch, CURLOPT_HTTPHEADER, array('passkey: '.$token));
$result = curl_exec($ch);
//$result = trim(preg_replace('[]','',curl_exec($ch)));
curl_close($ch);
如果 CURL 结果是"[1481367,7546218]",则将其转换为数组:
`$content = json_decode($result,TRUE); //Here $result = "[1481367,7546218]"`
使用变量打印变量$content
var_dump()
将输出:
array(2) {
[0] => int(1481367)
[1] => int(7546218)
}