我正在尝试从我收到的请求中的 ZOHO API 响应中填充下拉列表。我有两个文件。request.php 和 zoho.php。
我收到来自 request.php 的响应,如下所示。
object(stdClass)#2 (4) {
["code"]=>
int(0)
["message"]=>
string(7) "success"
["invoices"]=>
array(200) {
[0]=>
object(stdClass)#3 (54) {
["invoice_id"]=>
string(19) "2163791000003899301"
}
}
}
为了得到结果,我正在解码对象,如下所示
$result = curl_exec($ch);
curl_close($ch);
$decode_data = json_decode($result);
var_dump($decode_data);
我在 zoho.php 中有一个弹出窗口。
<select value="Select Zoho Invoice" name="zohoinvoice" id="zohoinvoice" class="SlectBox form-control">
<?php echo zohoFunc(); ?>
</select>
function zohoFunc(){
global $decode_data;
$output='';
$output .= '<option value = "Select Invoice">Select Invoice</option>';
foreach($decode_data as $inv){
$output[] .= '<option value = "'.$inv[0]->invoice_id.'">'.$inv[0]->invoice_number.'</option>';
}
return $output;
}
我循环接收到的数据的方式如下。我试图了解我们如何从 SQL 填充下拉列表,这是一个字符串,而 zoho 的情况下它是一个数组。我在哪里犯错误?