php – 表中的数组排列

我需要帮助,我对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应该是符合您规范格式的数组.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...