douzhigan1687 2016-03-23 16:08 采纳率: 0%
浏览 42
已采纳

PHP数组| “注意:使用未定义的常量..”或“注意:未定义的偏移量:0 ..”[关闭]

im trying to loop through my array, without success though..

Array

( 

    [Aircraft] => Array  
        (
            [0] => Array
                (
                    [A] => Gulfstream G100
                    [B] => Cessna Citation Excel
                    [C] => Cessna 208
                    [D] => Piper Aztec
                    [E] => Embraer ERJ 145
                    [F] => Airbus A330
                    [G] => Boeing Business Jet
                )


            [1] => Array

                (
                    [A] => Cessna Citation CJ3 
                    [B] => Dassault Falcon 900
                    [C] => Gulfstream G300
                    [D] => Boeing 767
                    [E] => ATR 42
                    [F] => Gulfstream IV
                    [G] => Airbus A320  
                )
        )
)

i have tried almost everything i can think of so far..

even..

print $data[0][A];

.. wount work.

My plan is to loop (foreach?) through this array..

please help me..

  • 写回答

4条回答 默认 最新

  • dpsfay2510 2016-03-23 16:14
    关注
    foreach($array['Aircraft'] as $array){
         echo $array['A'];
    }
    

    Have you tried something like this?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongzi3805 2016-03-23 16:13
    关注

    We need to see some code where you've tried to iterate through the array. You should be trying something like $data['aircraft'][0][A] to access a single item's value.

    Something like this should work to loop through:

    foreach ($array AS $aircraft) {
        echo $aircraft[A] . PHP_EOL;
    }
    
    // Gulfstream G100
    // Cessna Citation CJ3
    

    Hopefully enough to give you an idea.

    评论
  • dryift6733 2016-03-23 16:16
    关注

    Very easy way : use var_dump() or print_r() functions to dump variable in php
    But, for a specific needs, you have to think with recursive approach

    function loopRecursive($input) {
        foreach ($input as $key => $value ) {
            if (is_array($value)) {
                loopRecursive($value);
            }
            else {
                printf('Key: %s value: %s<br /> ',$key, $value);
            }                                  
        }
    }
    
    评论
  • doushe7934 2016-03-23 16:35
    关注

    Try this:

    foreach($array['Aircraft'] as $array){
        echo $array['A']." "; // Will print Gulfstream G100 Cessna Citation CJ3 
    }
    

    Hope this helps.

    Peace! xD

    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 stc12c5a60s2单片机测光敏ADC
  • ¥15 生信simpleaffy包下载
  • ¥15 请教一下simulink中S函数相关问题
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥
  • ¥15 Latex算法流程图行号自定义
  • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
  • ¥40 基于51单片机实现球赛计分器功能