I have an array called $topProductIdResults and it looks like the following:

我有一个名为$ topProductIdResults的数组,它看起来如下所示:

Array ( [11497522] => 2  ) 

The keys are prodcuct ID's and the value is the number of 5 star ratings that the product has recieved.

钥匙是产品ID,价值是产品收到的5星评级数。

I want it to echo out this data using a loop. However I can't work our how to echo out both the key and value. Sometimes there will be several product ID's and number pairs in this array. Please let me know where I'm going wrong. My code so far is:

我希望它使用循环回显这些数据。但是我无法理解我们如何回应键和值。有时在这个数组中会有几个产品ID和数字对。请让我知道我哪里出错了。到目前为止我的代码是:

foreach ($topProductIdResults as $prod) {
    echo $prod[0];
    echo $prod[1];
}

which just echo's 22 at the moment. I want it to echo 11497522 2

这只是回声的22。我希望它能回应11497522 2

4 个解决方案

#1


4

foreach ($topProductIdResults as $key => $value) {
    echo $key;
    echo $value;
}

更多相关文章

  1. 在多维数组中查找最小值并返回键
  2. 如何使用变量访问多维数组中的某些元素?
  3. 键入提示 - 指定对象数组
  4. 切出多维数组的一部分
  5. 仅获取单元素php数组中的值的最佳方法。
  6. 如何从其他文件调用数组
  7. php如何判断数组["a","b","c"]中是否含有"a"?
  8. 如何从databse中提取数据到2d数组中?
  9. (phpQuery)对网站产品信息采集代码的优化

随机推荐

  1. android mtk6732 camera otp 加载流程
  2. Android应用程序键盘(Keyboard)消息处理机
  3. android ImageView 设置背景选择器select
  4. android 判断网络时打开设置
  5. Android TextView各种使用方法
  6. android AlarmManager
  7. 如何让listview宽度自适应
  8. Android应用程序组件Content Provider的
  9. android adb am命令
  10. Android 去掉状态栏 去掉标题栏 沉浸式状