doujiang5211 2012-07-12 18:43
浏览 27
已采纳

了解多维数组的基础知识

I am new to using multidimensional arrays with php, I have tried to stay away from them because they confused me, but now the time has come that I put them to good use. I have been trying to understand how they work and I am just not getting it.

What I am trying to do is populate results based on a string compare function, once I find some match to an 'item name', I would like the first slot to contain the 'item name', then I would like to increment the priority slot by 1.

So when when I'm all done populating my array, it is going to have a variety of different company names, each with their respective priority...

I am having trouble understanding how to declare and manipulate the following array:

$matches = array(
    'name'=>array('somename'),
    'priority'=>array($priority_level++)
);
  • 写回答

6条回答 默认 最新

  • douju1852 2012-07-12 18:49
    关注

    So, in what you have, your variable $matches will point to a keyed array, the 'name' element of that array will be an indexed array with 1 entry 'somename', there will be a 'priority' entry with a value which is an indexed array with one entry = $priority_level.

    I think, instead what you probably want is something like:

    $matches[] = array(name => 'somename', $priority => $priority_level++);
    

    That way, $matches is an indexed array, where each index holds a keyed array, so you could address them as:

    $matches[0]['name'] and $matches[0]['priority'], which is more logical for most people.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题