Abdullah Amir Abdullah Amir - 1 month ago 8
PHP Question

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:

<?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]

is there anyway i can do that? I tried several solutions but none of them seemed to work for me.

Thanks

Answer

$matches[0] fetches the 0th index of the $matches array which also happens to be an array. You can just gran the 0th index of that as well.

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