只有一个双重foreach

时间:2014-03-17 22:47:23

标签: php database foreach laravel-4 blade

您好我怎样才能从此

中仅检索'fname'
array (size=1)
  0 => 
    array (size=6)
      'tcldbid' => int 7
      'tname' => 
        object(TeamSpeak3\Helper\String)[252]
          protected 'string' => string 'TEST' (length=4)
          protected 'position' => int 0
      'fcldbid' => int 2
      'fname' => 
        object(TeamSpeak3\Helper\String)[251]
          protected 'string' => string 'Pinky' (length=5)
          protected 'position' => int 0
      'message' => 
        object(TeamSpeak3\Helper\String)[256]
          protected 'string' => string 'aaaaaa' (length=6)
          protected 'position' => int 0
      'timestamp' => int 1395092502

我在laravel 4.1刀片中使用foreach

@foreach($p as $l)
@foreach($l as $key => $value)
{{$key . " " . $value}}</br>
@endforeach
@endforeach

这个foreach正在运行,但是当我想获取fname或仅消息时,我正在获取所有数据。任何人都可以帮助我吗?我新手开始学习php这样的例子会很好:)

1 个答案:

答案 0 :(得分:0)

无需循环,只需访问正确的数组元素:

$fname = $p[0]['fname'];
$message = $p[0]['message'];