简体   繁体   English

如何从php数组中获取特定值

[英]how to get specific value from php array

I have tried multiple solutions but none seems to work for me Basically I am pulling facebook page likes and it puts them in an array and then i want to display a specific value from that array but i am not able to do that no matter what, below is my code: 我已经尝试了多种解决方案,但似乎没有一种对我有用。基本上,我将“喜欢” Facebook页面并将其放入数组中,然后我想从该数组中显示特定值,但是无论如何我都无法做到这一点,下面是我的代码:

<?php

$url = 'https://graph.facebook.com/22992739859?fields=name,fan_count&access_token=my access token';

$t = file_get_contents($url);

preg_match_all('!\d+!', $t, $matches);

print_r($matches [0]);

?>

and the output is 输出是

Array ( [0] => 158060 [1] => 22992739859 )

I just want to get rid of the all the text except the value after [0] 我只想除去[0]之后的值以外的所有文本

is there anyway i can do that? 反正我能做到吗? I tried several solutions but none of them seemed to work for me. 我尝试了几种解决方案,但似乎没有一种适合我。

Thanks 谢谢

$matches[0] fetches the 0th index of the $matches array which also happens to be an array. $ matches [0]获取$ matches数组的第0个索引,该数组也恰好是一个数组。 You can just gran the 0th index of that as well. 您也可以只为其设置0th索引。

$result = $matches[0][0];
print_r($result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM