我想形成数组,如下所示。我如何在foreach中形成以下内容:
SELECT [rank] FROM table
ORDER BY
CASE
WHEN [rank] LIKE 'CHA%' THEN 1
WHEN [rank] LIKE 'MAS%' THEN 2
WHEN [rank] LIKE 'DIA%' THEN 3
WHEN [rank] LIKE 'PLA%' THEN 4
WHEN [rank] LIKE 'GOL%' THEN 5
WHEN [rank] LIKE 'SIL%' THEN 6
WHEN [rank] LIKE 'BRO%' THEN 7
WHEN [rank] LIKE 'Unranked' THEN 8
WHEN [rank] LIKE 'No Data' THEN 9
ELSE 10
END;
我的代码:
{
"status": "SUCCESS",
"totalRecords": 3,
"errorMessage": "",
"organizations": [
{
"organizationId": 1
},
{
"organizationId": 2
}
]
}
上面的代码,我想改变这样的事情:
$orgArray = array();
foreach($organizationInterface as $organization){
$orgArray[] = array(
'organizationId' => $organization->getId()
);
}
答案 0 :(得分:1)
根据我的理解,你想要这样的东西:
foreach($organizationInterface as $organization){
$orgArr['organizationId'][] = $organization->getId();
}
您不能在单个数组键上拥有多个值,这就是您想要在那里执行的操作。
答案 1 :(得分:0)
$jsonString = '{
"status": "SUCCESS",
"totalRecords": 3,
"errorMessage": "",
"organizations": [
{
"organizationId": 1
},
{
"organizationId": 2
}
]
}';
$jsonObj = json_decode($jsonString);
echo 'Status: ' . $jsonObj->status;
foreach($jsonObj->organizations as $org) {
echo 'Organization ID: ' . $org->organizationId;
}