我需要帮助,我对Array结果有问题.
我正在使用的代码:
$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应该是符合您规范格式的数组.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。