1

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 "=>").

1 Answer 1

3

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

echo $result[0]->ticker;
Sign up to request clarification or add additional context in comments.

1 Comment

omg thank you so much. I can't believe its so simple. I have probably written like 50 lines of code trying to parse this file. Thank you so much Alex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.