在 php 中解析数组时遇到问题
刚从 php 开始,抱歉,如果这是一个新手问题,但我在解析数组时遇到问题。
我得到这个值(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
)
)
)
我只想提取 ry-t 但不知道如何提取。这是我尝试过的
$result1 = implode('=>', $result);
print_r($result);
,
print (float)substr($result1, strpos($result1, "=")+1);
我研究了一些java和python,我试图应用相同的逻辑将其转换为字符串,然后通过分隔符分割文本(在本例中我认为“=>”)。
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 "=>").
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为数组成员添加下标,然后为
ticker
属性添加下标。You have to subscript the array member, and then the
ticker
property.