从嵌套对象中检索特定值
Retrieving specific values from nested object
如何从以下标准 class 中获取 Pro_photourl
和 id
值?
Array (
[0] => stdClass Object (
[Pro_photourl] => http://122.165.117.41/Commercial_Affairs/api/uploads/hd-panasonic-corporate16.jpg
[Pro_photoid] => 1150
)
[1] => stdClass Object (
[Pro_photourl] => http://122.165.117.41/Commercial_Affairs/api/uploads/beautiful-wallpaper-3948.jpg
[Pro_photoid] => 1150
)
[2] => stdClass Object (
[id] => 1150
[Pro_userid] => 252
[Pro_Listingtype] => Paid Listing
[Pro_membertype] => Owner
[Pro_purpose] => Rent
[Pro_type] => Business center
[Pro_subttype] => Commercial
[Pro_city] => Kochi
[Pro_locality] => Kerala, India
[Pro_society] =>
[Pro_addr_next] => kochi
[Pro_facility_washroom] =>
[Pro_facility_rooms] =>
[Pro_facility_rating] =>
[Pro_facility_balcony] =>
[Pro_facility_pooja_Room] =>
[Pro_facility_study_Room] =>
[Pro_facility_servant_Room] =>
[Pro_facility_others] =>
[Pro_furnishing] => Yes
[Pro_numberofproperty] => 1
[Pro_buildarea] => 700
[Pro_buildareaunit] => Sq.ft
[Pro_plotarea] => 0
[Pro_Plotareaunit] => NA
[Pro_carpetarea] =>
[Pro_carpetareaunit] =>
[Pro_price_crore] =>
[Pro_price_lakhs] =>
[Pro_price_thousand] =>
[Pro_pricefull] => 1000
[Pro_allprice] => YES
[Pro_pricenogotable] =>
[Pro_maintcharge] => 0
[Pro_maint_pmtmethod] =>
[Pro_transtype] => NA
[Pro_ownershiptype] => freehold
[Pro_availability] => readyToMove
[Pro_possessionperiod] => NA
[Pro_photoid] =>
[Pro_featuresid] =>
[Pro_description] => Test
[Pro_phonehide_disp] => yes
[Pro_regdate] => 2016-09-30 18:43:58
[Pro_bookingamt] =>
[Pro_anualduepayable] =>
[Pro_distfromairport] =>
[Pro_distfromHospital] =>
[Pro_distfromrailwaystation] =>
[Pro_distfromATM] =>
[Pro_Distfromcitycenter] =>
[Pro_distfromschool] =>
[Pro_keylandmark] =>
[Pro_adlcomments] =>
[Pro_verified] => Yes
[Pro_status] => Active
[Pro_unitprice] => 10000
[Pro_age] =>
[Expiry_Date] => 0
)
)
使用 foreach 浏览元素(使用 $arr 作为对象数组变量)
foreach($arr as $element){
echo $element->Pro_photourl;
echo $element->Pro_photoid;
}
//use
$arr[2]->id;
$arr[2]->Pro_userid
只需使用 foreach
来遍历每个 key/value 对
foreach($result as $key=>$row)
{
if(isset($row->Pro_photourl))
{
echo $row->Pro_photourl;
}
if(isset($row->Pro_userid))
{
echo $row->Pro_userid;
}
if(isset($row->id))
{
echo $row->id;
}
}
如果你想从 std class 中获取 Pro_photourl
和 id
的值,你可以使用:
<?php
foreach ($yourArr as $key => $value) {
if(isset($value->Pro_photourl)){
echo $value->Pro_photourl; // will print photourl if exist in object
}
if(isset($value->id)){
echo $value->id; // will print id if exist in object.
}
}
?>
因为根据您的 array
您有三个索引,两个索引具有 Pro_photourl
并且只有一个索引具有 id
值。
如何从以下标准 class 中获取 Pro_photourl
和 id
值?
Array (
[0] => stdClass Object (
[Pro_photourl] => http://122.165.117.41/Commercial_Affairs/api/uploads/hd-panasonic-corporate16.jpg
[Pro_photoid] => 1150
)
[1] => stdClass Object (
[Pro_photourl] => http://122.165.117.41/Commercial_Affairs/api/uploads/beautiful-wallpaper-3948.jpg
[Pro_photoid] => 1150
)
[2] => stdClass Object (
[id] => 1150
[Pro_userid] => 252
[Pro_Listingtype] => Paid Listing
[Pro_membertype] => Owner
[Pro_purpose] => Rent
[Pro_type] => Business center
[Pro_subttype] => Commercial
[Pro_city] => Kochi
[Pro_locality] => Kerala, India
[Pro_society] =>
[Pro_addr_next] => kochi
[Pro_facility_washroom] =>
[Pro_facility_rooms] =>
[Pro_facility_rating] =>
[Pro_facility_balcony] =>
[Pro_facility_pooja_Room] =>
[Pro_facility_study_Room] =>
[Pro_facility_servant_Room] =>
[Pro_facility_others] =>
[Pro_furnishing] => Yes
[Pro_numberofproperty] => 1
[Pro_buildarea] => 700
[Pro_buildareaunit] => Sq.ft
[Pro_plotarea] => 0
[Pro_Plotareaunit] => NA
[Pro_carpetarea] =>
[Pro_carpetareaunit] =>
[Pro_price_crore] =>
[Pro_price_lakhs] =>
[Pro_price_thousand] =>
[Pro_pricefull] => 1000
[Pro_allprice] => YES
[Pro_pricenogotable] =>
[Pro_maintcharge] => 0
[Pro_maint_pmtmethod] =>
[Pro_transtype] => NA
[Pro_ownershiptype] => freehold
[Pro_availability] => readyToMove
[Pro_possessionperiod] => NA
[Pro_photoid] =>
[Pro_featuresid] =>
[Pro_description] => Test
[Pro_phonehide_disp] => yes
[Pro_regdate] => 2016-09-30 18:43:58
[Pro_bookingamt] =>
[Pro_anualduepayable] =>
[Pro_distfromairport] =>
[Pro_distfromHospital] =>
[Pro_distfromrailwaystation] =>
[Pro_distfromATM] =>
[Pro_Distfromcitycenter] =>
[Pro_distfromschool] =>
[Pro_keylandmark] =>
[Pro_adlcomments] =>
[Pro_verified] => Yes
[Pro_status] => Active
[Pro_unitprice] => 10000
[Pro_age] =>
[Expiry_Date] => 0
)
)
使用 foreach 浏览元素(使用 $arr 作为对象数组变量)
foreach($arr as $element){
echo $element->Pro_photourl;
echo $element->Pro_photoid;
}
//use
$arr[2]->id;
$arr[2]->Pro_userid
只需使用 foreach
来遍历每个 key/value 对
foreach($result as $key=>$row)
{
if(isset($row->Pro_photourl))
{
echo $row->Pro_photourl;
}
if(isset($row->Pro_userid))
{
echo $row->Pro_userid;
}
if(isset($row->id))
{
echo $row->id;
}
}
如果你想从 std class 中获取 Pro_photourl
和 id
的值,你可以使用:
<?php
foreach ($yourArr as $key => $value) {
if(isset($value->Pro_photourl)){
echo $value->Pro_photourl; // will print photourl if exist in object
}
if(isset($value->id)){
echo $value->id; // will print id if exist in object.
}
}
?>
因为根据您的 array
您有三个索引,两个索引具有 Pro_photourl
并且只有一个索引具有 id
值。