我需要帮助,我对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应该是符合您规范格式的数组.
标签:php,arrays
来源: https://codeday.me/bug/20190623/1274769.html