array(1) { ["result"]=> array(3) { ["timestamp"]=> string(19) "2021-08-12 08:23:50" ["api"]=> string(17) "Spot Rate USD/THB" ["data"]=> array(2) { ["data_header"]=> array(7) { ["report_name_eng"]=> string(24) "Spot Rate and Swap Point" ["report_name_th"]=> string(24) "Spot Rate and Swap Point" ["report_uoq_name_eng"]=> string(0) "" ["report_uoq_name_th"]=> string(0) "" ["report_source_of_data"]=> array(2) { [0]=> array(2) { ["source_of_data_eng"]=> string(27) "Thomson Reuters (Refinitiv)" ["source_of_data_th"]=> string(27) "Thomson Reuters (Refinitiv)" } [1]=> array(2) { ["source_of_data_eng"]=> string(16) "Bank of Thailand" ["source_of_data_th"]=> string(57) "ธนาคารแห่งประเทศไทย" } } ["report_remark"]=> array(3) { [0]=> array(2) { ["report_remark_eng"]=> string(83) "Forward exchange rate can be derived from the addition of spot rate and swap point." ["report_remark_th"]=> string(183) "อัตราแลกเปลี่ยนล่วงหน้าคำนวณได้จากอัตราแลกเปลี่ยนทันที และ SWAP POINT" } [1]=> array(2) { ["report_remark_eng"]=> string(109) "This table has been discontinued due to redundancy with other tables on the BOT website or original sources." ["report_remark_th"]=> string(349) "ตารางนี้ถูกยกเลิกการเผยแพร่ เนื่องจากข้อมูลมีการเผยแพร่ในตารางอื่นของ ธปท. หรือหน่วยงานอื่นที่เป็นเจ้าของข้อมูลอยู่แล้ว" } [2]=> array(2) { ["report_remark_eng"]=> string(21) "1 Satang = 0.01 Baht." ["report_remark_th"]=> string(40) "1 สตางค์ = 0.01 บาท " } } ["last_updated"]=> string(10) "2021-08-03" } ["data_detail"]=> array(4) { [0]=> array(3) { ["period"]=> string(10) "2021-06-07" ["bid_rate"]=> string(10) "31.1900000" ["offer_rate"]=> string(10) "31.2000000" } [1]=> array(3) { ["period"]=> string(10) "2021-06-04" ["bid_rate"]=> string(10) "31.2700000" ["offer_rate"]=> string(10) "31.2800000" } [2]=> array(3) { ["period"]=> string(10) "2021-06-02" ["bid_rate"]=> string(10) "31.1500000" ["offer_rate"]=> string(10) "31.1600000" } [3]=> array(3) { ["period"]=> string(10) "2021-06-01" ["bid_rate"]=> string(10) "31.1400000" ["offer_rate"]=> string(10) "31.1500000" } } } } }
result = Array
timestamp = 2021-08-12 08:23:50
api = Spot Rate USD/THB
report_name_eng = Spot Rate and Swap Point
report_name_th = Spot Rate and Swap Point
report_uoq_name_eng =
report_uoq_name_th =
source_of_data_eng = Thomson Reuters (Refinitiv)
source_of_data_th = Thomson Reuters (Refinitiv)
source_of_data_eng = Bank of Thailand
source_of_data_th = ธนาคารแห่งประเทศไทย
report_remark_eng = Forward exchange rate can be derived from the addition of spot rate and swap point.
report_remark_th = อัตราแลกเปลี่ยนล่วงหน้าคำนวณได้จากอัตราแลกเปลี่ยนทันที และ SWAP POINT
report_remark_eng = This table has been discontinued due to redundancy with other tables on the BOT website or original sources.
report_remark_th = ตารางนี้ถูกยกเลิกการเผยแพร่ เนื่องจากข้อมูลมีการเผยแพร่ในตารางอื่นของ ธปท. หรือหน่วยงานอื่นที่เป็นเจ้าของข้อมูลอยู่แล้ว
report_remark_eng = 1 Satang = 0.01 Baht.
report_remark_th = 1 สตางค์ = 0.01 บาท
last_updated = 2021-08-03
period = 2021-06-07
bid_rate = 31.1900000
offer_rate = 31.2000000
period = 2021-06-04
bid_rate = 31.2700000
offer_rate = 31.2800000
period = 2021-06-02
bid_rate = 31.1500000
offer_rate = 31.1600000
period = 2021-06-01
bid_rate = 31.1400000
offer_rate = 31.1500000
+ bot_api_us2thai.htm
+ bot_api_us2thai.php
+ bot_api_us2thai_test.php
<?php
header("content-type:text/html;charset=utf-8"); 
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://apigw1.bot.or.th/bot/public/Stat-SpotRate/v2/SPOTRATE/?start_period=2021-06-01&end_period=2021-06-07",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "x-ibm-client-id: xxxx"
  ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $thai_data = $response;
}
var_dump(json_decode($thai_data,true)); // array
$d = json_decode($thai_data,true); //array
echo "<hr/>";
foreach($d as $k => $v) {
	echo "<b>$k = $v</b><br/>"; 
	forarray($k,$d);
}
// -------------------
function forarray($k,$d) {
	if(is_array($d)) {
		foreach($d as $k => $v) { 
			if(is_array($v)) {
				forarray($k,$v);
			} else echo "<span style='color:blue;'>$k = $v</span><br/>"; 
		}
	} 
}
?>