in_array/array_search always find everything
Posted: Wed Jan 19, 2011 10:15 am
Hey,
I am trying to write a log in that requires the user to be a member of a secret facebook group. Hence, I am asking user for permission to access his groups list and then fetch it and try to search for the specific group ID. For some reason in_array and array_search always find whatever I am searching for. You can try here: http://quadro-design.org/uj/index.php (I promise to delete you from the list of people who gave access to their profiles afterwards!)
The relevant code for what is done is this,
and the relevant result is this.
How come that "version" => 0 or "administrator" => true are found when searching for LALALA??
Thanks so much!
Lars
I am trying to write a log in that requires the user to be a member of a secret facebook group. Hence, I am asking user for permission to access his groups list and then fetch it and try to search for the specific group ID. For some reason in_array and array_search always find whatever I am searching for. You can try here: http://quadro-design.org/uj/index.php (I promise to delete you from the list of people who gave access to their profiles afterwards!)
The relevant code for what is done is this,
Code: Select all
$ch = curl_init('https://graph.facebook.com/me/groups?access_token=' . $fb_cookie['access_token']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$user_groups = json_decode(curl_exec($ch),true);
curl_close($ch);
foreach ($user_groups['data'] as $key => $value) {
var_dump($value);
var_dump(array_search("LALALA", $value));
echo '<br />';
Code: Select all
array(3) { ["version"]=> int(0) ["name"]=> string(19) "Facebook Developers" ["id"]=> string(10) "2205007948" } string(7) "version"
array(4) { ["version"]=> int(1) ["name"]=> string(13) "UJ Test Group" ["id"]=> string(15) "145134142210424" ["administrator"]=> bool(true) } string(13) "administrator"
array(4) { ["version"]=> int(0) ["name"]=> string(5) "ICMUN" ["id"]=> string(10) "2210610727" ["administrator"]=> bool(true) } string(7) "version"
array(3) { ["version"]=> int(0) ["name"]=> string(21) "OxIMUN 2010 - SPECPOL" ["id"]=> string(15) "106393712753441" } string(7) "version"
array(3) { ["version"]=> int(0) ["name"]=> string(54) "OxIMUN 2010- Oxford International Model United Nations" ["id"]=> string(15) "113685065319968" } string(7) "version"
array(3) { ["version"]=> int(0) ["name"]=> string(20) "Thinking Development" ["id"]=> string(15) "129667607051176" } string(7) "version"
array(3) { ["version"]=> int(0) ["name"]=> string(27) "Imperial College Yacht Club" ["id"]=> string(10) "2204176629" } string(7) "version"
[...]
Thanks so much!
Lars