我需要帮助,数组结果有问题。
我使用的代码:
$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
最佳答案
您只需使用foreach迭代并将所需的输出构建到输出数组中,如下所示
foreach ($presents as $key=>$value) {
$newKey = $key + 1;
$output[$newKey] = "Sender ID: {$value['sender']} and Item Code is {$value['itemCode']}";
}
其中
$output
应该是按照您的规范格式化的数组。