-4

This is the array

$resultData2 = array ( 
    0 => array ( 
        "email" => "abcd@gmail.com", 
        "fname" => "sachin" 
    ) 
);

How can I access each value such as email, fname?

I am trying to access it like this :

echo $resultData2[0]->email;

What am I doing wrong?

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36

3 Answers3

0

You have an array :

$resultData2 = array(
    0 => array(
        "email" => "abcd@gmail.com",
        "fname" => "sachin"
    )
);

You are doing echo $resultData2[0]->email;, but this is the syntax if $resultData2[0] was a object.

With array, use echo $resultData2[0]['email'];

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
0
    $email = array_column( $array,'email');
    $fname = array_column($array,'fname');
TsV
  • 629
  • 4
  • 7
0

Try using foreach loop.

foreach($resultData2 as $resultData)
{
    echo $resultData['email'];
}
Leena Patel
  • 2,423
  • 1
  • 14
  • 28