Question

Hi how can I retrieve only 'fname' from this

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

I am using foreach in laravel 4.1 blade

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

This foreach is working but I am getting all data when I want to get fname or message only. Can anyone help me with that? I newbie who started learning php so example would be nice :)

Was it helpful?

Solution

No need to loop, you can just access the correct array element:

$fname = $p[0]['fname'];
$message = $p[0]['message'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top