给定字符串值时从PHP数组提取数据
我想根据给定的信息从PHP数组中提取信息 Php是给定字符串值时从PHP数组提取数据,php,arrays,Php,Arrays,我想根据给定的信息从PHP数组中提取信息 Php是 $xmlstring = file_get_contents('http://www.bookingassist.ro/XML/test.xml'); $xml = simplexml_load_string($xmlstring); $json = json_encode($xml); $array = json_decode($json,TRUE); $HotelCodes[] = array('BG01I9', 'BG53I4', 'BG
$xmlstring = file_get_contents('http://www.bookingassist.ro/XML/test.xml');
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
$HotelCodes[] = array('BG01I9', 'BG53I4', 'BG23I7');
$code = $HotelCodes[1];
if (!$code) {
throw new Exception("No Hotel Code specified");
}
foreach ($HotelCodes as $code) {
foreach ($hotels as $hotel) {
if (strcasecmp($hotel['HotelCode'], $code) === 0) {
echo "{$hotel['Latitude']}:{$hotel['Longitude']}<br/>";
foreach ($hotel['HotelImages']['ImageUrl'] as $img) {
echo "<img src='{$img}'/><hr/>";
}
break;
}
}
}
我想根据我提供的酒店代码回显酒店图像、纬度和经度:
酒店代码为$HotelCodes[0]
收到的错误是:
Fatal error: Uncaught exception 'Exception' with message 'No Hotel Code specified' in /home/truckass/public_html/site/test/teste.php:10 Stack trace: #0 {main} thrown in /home/truckass/public_html/siteo/test/teste.php on line 10
我需要回显酒店代码[1]
$img[1][0] ....$img[1][5]
$Latitude[1]
$Longitude[1]
请您协助。循环数组并检查
HotelCode
是否与指定的匹配:
$HotelCodes = array('BG01I9', 'BG53I4', 'BG23I7');
if (!$code) {
throw new Exception("No Hotel Code specified");
}
foreach ($HotelCodes as $code) {
foreach ($hotels as $hotel) {
if (strcasecmp($hotel['HotelCode'], $code) === 0) {
echo "{$hotel['Latitude']}:{$hotel['Longitude']}<br/>";
foreach ($hotel['HotelImages']['ImageUrl'] as $img) {
echo "<img src='{$img}'/><hr/>";
}
break;
}
}
}
$HotelCodes=array('BG01I9','BG53I4','BG23I7');
如果(!$code){
抛出新异常(“未指定酒店代码”);
}
foreach($HotelCodes作为$code){
foreach($hotels as$hotel){
if(strcasecmp($hotel['HotelCode',$code)==0){
echo“{$hotel['Latitude']}:{$hotel['Latitude']}
”;
foreach($img形式的酒店['HotelImages']['ImageUrl']{
回声“
”;
}
打破
}
}
}
您能显示任何代码吗?@mc10请检查问题。@segarci请检查问题。谢谢,但我不明白如何定义酒店代码。在我的页面中,HotelCode的定义为:$HotelCodes[0]、$HotelCodes[1]、$HotelCodes[2]、$酒店代码[x]
$HotelCodes = array('BG01I9', 'BG53I4', 'BG23I7');
if (!$code) {
throw new Exception("No Hotel Code specified");
}
foreach ($HotelCodes as $code) {
foreach ($hotels as $hotel) {
if (strcasecmp($hotel['HotelCode'], $code) === 0) {
echo "{$hotel['Latitude']}:{$hotel['Longitude']}<br/>";
foreach ($hotel['HotelImages']['ImageUrl'] as $img) {
echo "<img src='{$img}'/><hr/>";
}
break;
}
}
}