私は次の値を持っています:-
私が欲しいもの:-市コードから市名を取得したいですか?
例:- 入力が「BA」の場合、「Bagmati」を表示したい、入力が「DH」の場合、「Dhawlagiri」を表示したい
$value = '{"NP":{
"1" : {"code":"BA","name":"Bagmati"},
"2" : {"code":"BH","name":"Bheri"},
"3" : {"code":"DH","name":"Dhawalagiri"},
"4" : {"code":"GA","name":"Gandaki"},
"5" : {"code":"JA","name":"Janakpur"},
"6" : {"code":"KA","name":"Karnali"},
"7" : {"code":"KO","name":"Kosi"},
"8" : {"code":"LU","name":"Lumbini"},
"9" : {"code":"MA","name":"Mahakali"},
"10" : {"code":"ME","name":"Mechi"},
"11" : {"code":"NA","name":"Narayani"},
"12" : {"code":"RA","name":"Rapti"},
"13" : {"code":"SA","name":"Sagarmatha"},
"14" : {"code":"SE","name":"Seti"}
}';
私が試したことPHP
:-
$value = json_decode($json);
//print_r($value);
foreach ($value->IN->code as $city) {
echo $city->name;
}
しかし、よくわかりません。どうすればこれを入手できますか。どんな助けでも大歓迎です。
念のため、ファイルからこれらの値を取得しましたjavascript
:-state.jsファイル
"NP":{
"1" : {"code":"BA","name":"Bagmati"},
"2" : {"code":"BH","name":"Bheri"},
"3" : {"code":"DH","name":"Dhawalagiri"},
"4" : {"code":"GA","name":"Gandaki"},
"5" : {"code":"JA","name":"Janakpur"},
"6" : {"code":"KA","name":"Karnali"},
"7" : {"code":"KO","name":"Kosi"},
"8" : {"code":"LU","name":"Lumbini"},
"9" : {"code":"MA","name":"Mahakali"},
"10" : {"code":"ME","name":"Mechi"},
"11" : {"code":"NA","name":"Narayani"},
"12" : {"code":"RA","name":"Rapti"},
"13" : {"code":"SA","name":"Sagarmatha"},
"14" : {"code":"SE","name":"Seti"}
},
ありがとうございました!