Php 我使用curl作为json对象从api获取数据,它提供了一个数组,我想将其绑定到下拉列表中

Php 我使用curl作为json对象从api获取数据,它提供了一个数组,我想将其绑定到下拉列表中,php,json,curl,Php,Json,Curl,现在我想把它绑定到下拉列表中,怎么做?我不知道如何使用api数据作为数组来创建drio down 如果有帮助,请看一看 $arr = json_decode($response); foreach($arr['items'] as $val) { echo $val['fieldname'].'<br>'; } $arr=json\u解码($response); foreach($arr['items']作为$val) { echo$val['fieldnam

现在我想把它绑定到下拉列表中,怎么做?我不知道如何使用api数据作为数组来创建drio down


如果有帮助,请看一看

$arr = json_decode($response);
foreach($arr['items'] as $val)
{
    echo $val['fieldname'].'<br>';       
}
$arr=json\u解码($response);
foreach($arr['items']作为$val)
{
echo$val['fieldname'].
; }
我想这就是你的意思——不管怎么说,都是这样。我不能百分之百确定我使用了正确的钥匙

<?php

    $baseurl = 'http://host/api/v1/specializations';
    $headers=array(
        "Content-Type: application/json",
        "Authorization: Bearer $atoken"
    );
    $data = array( "type" => "private" );


    $curl = curl_init( $baseurl );
    curl_setopt( $curl, CURLOPT_POST, true );
    curl_setopt( $curl, CURLOPT_HEADER, false );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers ); 
    curl_setopt( $curl, CURLOPT_POSTFIELDS, json_encode( $data ) );
    $result = curl_exec( $curl );
    curl_close( $curl );

    if( $result ) {
        if ( isset($result->error) )die( $result->error_message );
        /* Convert json data to array */
        $arr=json_decode( $result, true );

        /* Items of interest for menu are here? */
        $json=$arr['data']['specialityMap'];

        /* empty array to populate with html content */
        $html=array();
        /* add to the array */
        $html[]="<select name=''>";
        foreach($json as $i => $v )$html[]="<option value='$i'>$v";
        $html[]="</select>";

        /* echo or return html menu */
        echo implode( PHP_EOL, $html );
    }

?>