phpphp-parser

having trouble parsing an array in php


Just starting with php and sorry if this is a newbie question but i'm having problems parsing a array.

I get this value(output of print_r($result);):

Array ( 
  [0] => stdClass Object ( 
       [Master_companyname] => Royal Bank of Canada 
       [ticker] => ry-t 
       [base_table] => Master 
       [base_field] => ticker 
       [set] => 
           [rendered] =>
              Companyname:
              Ticker:
              Companyname:
       [finder_element_1_Master_companyname] => Royal Bank of Canada 
       [field_names] => Array ( 
            [1] => finder_element_1_Master_companyname 
            ) 
       ) 
   )

I want to extract only ry-t but not sure how. Here's what I tried

$result1 = implode('=>', $result);
print_r($result);

and

print (float)substr($result1, strpos($result1, "=")+1);

I studied a bit of java and python and I was trying to apply the same logic of converting it to a string and then splitting the text by a delimiting(in this case I thought "=>").


Solution

  • You have to subscript the array member, and then the ticker property.

    echo $result[0]->ticker;