php - Codeigniter XML-RPC Response Multi Dimensional Array Approach -
i need create xml-rpc server gets cities corresponding ids. response looking weird me because of unnecessary duplicate entries couldnt find better way.
array ( [cityid] => array ( [0] => 34 [1] => 35 [2] => 06 ) [cityname] => array ( [0] => istanbul [1] => izmir [2] => ankara ) )
i implemented above response. implementation:
$response = array( array( 'cityid' => array(array('34', '35', '06'), 'array'), 'cityname' => array(array('istanbul', 'izmir', 'ankara'), 'array') ), 'struct' );
the problem want take response :
array ( [cities] => array ( ['34'] => 'istanbul' ['35'] => 'izmir' ['06'] => 'ankara' ) )
so tried implement :
$response = array( array( 'cities' => array(array('34'=>'istanbul', '35'=>'izmir', '06'=>'ankara'), 'array') ), 'struct' );
but fails implementation. doing wrong ?
thanks
you have array following
$response = array ( 'cityid' => array ( 0 => 34, 1 => 35, 2 => 06 ), 'cityname' => array( 0 => 'istanbul', 1 => 'izmir', 2 => 'ankara' ) ); $newarray = array(); foreach($response['cityid'] $key => $cityid){ $newarray['cities'][$cityid] = $response['cityname'][$key]; } print_r($newarray);
you getting expected array.
array ( [cities] => array ( [34] => istanbul [35] => izmir [6] => ankara ) )
Comments
Post a Comment