dswfyq6201 2015-04-29 18:47
浏览 35
已采纳

在另一个数组中索引为1的数组中的行索引1

I have searched for hours and cannot find the answer.

I have 2 arrays that will always be the same length

array_a(12, 13, 14);

array_b(15, 18, 20);

How would I print to 3 different variables (or arrays) like so...

$array_c(12, 15);

$array_d(13, 18);

$array_e(14, 20);

So they line up.

Thanks

Okay I figured it out. I guess I should explain what I was trying to do better so that the code is easier to understand. I have an application in which a user can enter room sizes for the square footage of a room. Because all rooms are not always square, I wanted to be able to allow the user who had a "L" shaped room to divide the room up and enter multiple measurements for each room. So they could add another row to a table to add the length and width for the bottom of the "L". (I know its hard to explain) Anyway, the user could submit 2 squares for a room that is odd shaped. Since my database only has 1 row per room, I figured it would be better to add multiple measurements inside of the same field separated by a space which I could explode later if I need to. Anyway, this is what I came up with

$width = $_POST['width']; //an array
    $length = $_POST['length']; //an array
    $dimensions_array = array();
        foreach ($width as $key => $value) {
            $individual_length = $length[$key];
            array_push($dimensions_array, $value.'x'.$individual_length);
        }
        $dimensions = implode(' ', $dimensions_array);

This returns an array called $dimensions that is (12x15 13x18 14x20)

  • 写回答

1条回答 默认 最新

  • dtwknzk3764 2015-04-29 20:17
    关注
    $width = $_POST['width']; //an array
    $length = $_POST['length']; //an array
    $dimensions_array = array();
        foreach ($width as $key => $value) {
            $individual_length = $length[$key];
            array_push($dimensions_array, $value.'x'.$individual_length);
        }
        $dimensions = implode(' ', $dimensions_array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应