dtdfl62844 2013-04-06 16:11
浏览 47
已采纳

php - 矩阵 - 我在哪里弄错了?

Create a program with the following output:

a 00000000
b 00000000
c 00000X00
d 00000000
e 00000000
f 000X0000
g 00000000
h 00000X00
12345678

The user enters two-dimensional array at the beginning of the program. Based on this sequence (coordinates) are drawn X's on the table.

Conditions: Must be used arrays and loops.

I`m 18 and I started to learn php 2 weeks ago. Im having trouble with this task. Can anyone help me ? THANKS!

SORRY!

this is what I`ve done:

<?php
$input = array(2 => array(5),5 => array(3),7 => array(6));
$range = array('a','b','c','d','e','f','g','h');
$length = 8;

$output = '';
foreach($range as $index => $letter)
{
$output .= "$letter ";

for($i = 0; $i < $length; ++$i)
{
$output .= (array_key_exists($index, $input) && in_array($i, $input[$index])) ? 'X' : '0';
}

$output .= "
";
}

echo $output;
?>

i got this output:

a 00000000
b 00000000
c 00000X00
d 00000000
e 00000000
f 000X0000
g 00000000
h 000000X0

instead of this:

a 00000000
b 00000000
c 00000X00
d 00000000
e 00000000
f 000X0000
g 00000000
h 00000X00
12345678

Where I am making a mistake?

  • 写回答

2条回答 默认 最新

  • dpl57372 2013-04-06 17:12
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题