douqiao3930 2012-05-25 18:13
浏览 16

PHP网格类型数组获取行或列

This may sound like a silly question and I'm not thinking hard enough,

Or its harder than i think...

Say i have a array of numbers like:

$table = array(
'5','2','1','4','4','4',
'1','2','4','2','1','1',
'3','4','3','1','4','4',
'1','4','2','S','4','4',
'1','2','4','2','1','1',
'5','2','6','4','8','1'
);

S = where I want to get either the row or column based on where "S" is.

I know i can get where S is.

by doing:

$start = array_search('S', $table);

The ''grid'' this array is based on,The S can can be anywhere.

And the grid itself can be different sizes length and width.

How would i go about getting the whole row or column.?

(IE:S is in column 3 : 4,2,1,S,2,4)

(IE:S is in row 3 : 1,4,2,S,4,4)

Just a hint in the right direction would be helpful, Don't need to go all out for me.

Or a idea on how to approach this.

  • 写回答

3条回答 默认 最新

  • douhan1860 2012-05-25 18:17
    关注

    Here is a hint:

    $table[] = array();
    $table[][0] = array(5,2,1,4,5);
    $table[][1] = array(1,5,2,3,3);
    $table[][2] = array(1,2,'s',4,5);
    

    You will need an array of arrays to have an x/y search.

    Your x is the nth element in the outer array.

    Your y is the nth element in the inner array.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据