我需要帮助,我遇到数组结果的问题。
我使用的代码:
$presents = json_decode(fBGetDataStore('presents'), true);
并打印结果:
<?= print_r($presents) ?>
显示结果:
Array ( [0] => Array ( [sender] => 100009016810227 [itemCode] => 0f8g [itemContext] => normal [extraData] => )
[1] => Array ( [sender] => 100009016810227 [itemCode] => 0fcm [itemContext] => normal [extraData] => )
但我想要结果:
[1] Sender ID: 100009016810227 and Item Code is 0f8g
[2] Sender ID: 100009016810227 and Item Code is 0fcm
答案 0 :(得分:2)
你可以简单地用foreach迭代并将所需的输出构建到输出数组中,就像这样
foreach ($presents as $key=>$value) {
$newKey = $key + 1;
$output[$newKey] = "Sender ID: {$value['sender']} and Item Code is {$value['itemCode']}";
}
$output
应该是符合您规范格式的数组。
答案 1 :(得分:2)
我按照你说的那样做了@FatAdama
编码:
foreach ($presents as $key=>$value) {
echo 'Sender ID: '.$value['sender'].' and Item Code is '.$value['itemCode'].'<br>';
}
我得到了我想要的结果^ _ ^:
Sender ID: 100009016810227 and Item Code is 0f8g
Sender ID: 100009016810227 and Item Code is 0fcm
感谢您的帮助。