我有以下代码:
$responseretrieveUserDetails = CRSMClient::retrieveUserDetails($userId);
echo "<pre>";
print_r($responseretrieveUserDetails);
echo "</pre>";
$obj = json_decode($responseretrieveUserDetails );
$autoFlag = false;
$prod = false;
$log = false;
$mac = false;
$auto = "";
$value = 0;
foreach($obj["userAttributeList"]["attributeValues"] as $key => $val){
$auto = $val["attributeName"];
$value = $val["attributeValue"];
if($auto == "Auto" && $value == 1){
$autoFlag = true;
}
if($auto == "Prod" && $value == 1){
$prod = true;
}
if($auto == "Logistics" && $value == 1){
$log = true;
}
if($auto == "Mac" && $value == 1){
$mac = true;
}
}
$ responseretrieveUserDetails返回以下内容:
(
[id] => 636
[description] => customer2802@camera.com
[parentBusinessUserId] => 155
[statusId] => 1
[roleTypeId] => 49
[defaultLanguageId] => 2
[userExternalIdList] => Array
(
[externalIds] => Array
(
[0] => Array
(
[externalId] => customer2802@camera.com
[defaultFlag] => 1
[type] => email
[statusId] => 1
)
)
)
[userAttributeList] => Array
(
[attributeValues] => Array
(
[0] => Array
(
[attributeId] => 9
[attributeName] => name
[attributeValue] => customer2802@camera.com
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[1] => Array
(
[attributeId] => 100015
[attributeName] => Mac
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[2] => Array
(
[attributeId] => 100014
[attributeName] => Logistics
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[3] => Array
(
[attributeId] => 100018
[attributeName] => timezone
[attributeValue] => GMT+00:00
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[4] => Array
(
[attributeId] => 14
[attributeName] => email
[attributeValue] => myemail@mail.com
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[5] => Array
(
[attributeId] => 100012
[attributeName] => Auto
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[6] => Array
(
[attributeId] => 100013
[attributeName] => Prod
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[7] => Array
(
[attributeId] => 100007
[attributeName] => TC_WEB
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[8] => Array
(
[attributeId] => 100009
[attributeName] => TC_Vx_WEB
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
)
)
[offeringList] => Array
(
[offerings] => Array
(
[0] => Array
(
[id] => 16
[name] => CAM
[statusId] => 1
)
)
)
[offeringDetailsRetrievedList] => Array
(
[0] => Array
(
[id] => 16
[name] => CAM
[statusId] => 1
)
)
[businessUserAttributeList] => Array
(
[0] => Array
(
[attributeId] => 9
[attributeName] => name
[attributeValue] => customer2802@camera.com
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[1] => Array
(
[attributeId] => 100015
[attributeName] => Mac_Operator
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[2] => Array
(
[attributeId] => 100014
[attributeName] => Logistics
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[3] => Array
(
[attributeId] => 100018
[attributeName] => timezone
[attributeValue] => GMT+00:00
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[4] => Array
(
[attributeId] => 14
[attributeName] => email
[attributeValue] => myemail@mail.com
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[5] => Array
(
[attributeId] => 100012
[attributeName] => Auto_Maintenance
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[6] => Array
(
[attributeId] => 100013
[attributeName] => Prod_Director
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[7] => Array
(
[attributeId] => 100007
[attributeName] => TC_WEB
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
[8] => Array
(
[attributeId] => 100009
[attributeName] => TC_Vx_WEB
[attributeValue] => 1
[languageId] => 2
[languageName] => en
[statusId] => 1
[statusName] => active
)
)
[externalId] => customer2802@camera.com
[externalIdType] => email
[mail] => myemail@mail.com
)
我不知道我的代码有什么问题,但是我的foreach语句未返回任何内容?我想获取Mac,Prod,Auto和Logistics的attributeName和属性值的值,如果属性值为1,则返回true,如果属性值为零,则返回false。帮助吗?