douyou2234 2019-02-11 13:31
浏览 52

如何为数组中的每个数组编写代码

I am new to this so please do not judge.

  1. I have transformed a .csv file into an array([0]=>array([0]=>string(), [1]=>string())[1]=>array([0]=>string(), [1]=>string()) etc. So I can access it numerically i.e. $the_big_array[1][1]

  2. Now I want the program to write a couple of lines of code for each array within an array.

  3. Basically what I am doing is creating a table like this that will be encoded in json.

    $request['AddPrice'][0][variable1] = $the_big_array[1][2] $request['AddPrice'][0][variable2] = $the_big_array[1][3]

and I want different values loaded for and from each line of .csv file/$the_big_array

$request['AddPrice'][1][variable1] = $the_big_array[1][2]
$request['AddPrice'][1][variable2] = $the_big_array[1][3]

I am stuck at foreach function as I cannot grasp how to make it execute certain action for each array within an array.

  • 写回答

2条回答 默认 最新

  • dongxiezhuo8852 2019-02-11 15:45
    关注

    You have to use a foreach loop for every array dimension. If You have 2 dimensions, like in $the_big_array[1][1], go through the first dimension with your first loop. Inside this loop, do another foreach to go through your second dimension.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)