输出Laravel阵列密钥列表

时间:2016-11-08 15:08:11

标签: php arrays laravel laravel-5

返回我的变量$ data时,我有以下内容;

{
"Test Location":
[{"name":"Kieran","round":"Test Location"},{"name":"Jordan","round":"Test Location"}],
"Location 2":
[{"name":"Paul Sample","round":"Location 2"}]
}

如何输出此示例中的唯一键

  • 测试位置
  • 位置2

我试过

<ul>
                    @foreach($rounds as $r => $name)
                        <li>{{ $name }}</li>
                    @endforeach
                </ul>

但是这给了我钥匙内的数据。

希望我有意义。

2 个答案:

答案 0 :(得分:1)

您可以尝试:

<ul>
                @foreach($rounds as $r => $name)
                    <li>{{ $r }}</li>
                @endforeach
            </ul>

@foreach($rounds as $r => $name)中,$r是关键,$name是值。

答案 1 :(得分:0)

数据集包含Thread,因此您需要迭代数据集两次。

试试这个:

class Example extends JPanel{

    public Dimension getPreferredSize(){
        return new Dimension(500, 500);
    }

    public void paintComponent(Graphics g){
        super.paintComponent(g);
        draw(g);
    }

    public void draw(Graphics g){
        BufferedImage temp1;
        BufferedImage temp2;
        try{
            temp1 = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\test1.png"));
            temp2 = ImageIO.read(new File("C:\\Users\\Owner\\Desktop\\test2.png"));
        }catch(IOException e){
            temp1 = null;
            temp2 = null;
        }
        final BufferedImage image1 = temp1;
        final BufferedImage image2 = temp2;
        Thread drawThread = new Thread(new Runnable(){
            public void run(){
                g.drawImage(image1, 0, 0, null);
                try{
                    Thread.sleep(100);
                }catch(InterruptedException e){
                    // omitted
                }
                g.drawImage(image2, 0, 0, null);
                try{
                    Thread.sleep(100);
                }catch(InterruptedException e){
                    // omitted
                }
            }
        });
        drawThread.start();
    }

    public static void main(String[] args){
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new B());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
           }
        });
    }

}