使用FQL的Facebook PHP SDK生日应用
我是PHP编程的新手。我使用 FQL 查询来获取所有用户朋友的生日。 但我想根据月份和日期对用户进行排序。在多维阵列中可以做到这一点吗?我想要:
$year = array('jan' => array('1' => array(data returned by fql query), '2' => array(data returned by fql query),..etc), 'feb' => array('1' => array(data returned by fql query)), 'mar' => array(), etc);
有可能吗? 到目前为止,我的代码:
$query = "SELECT uid, first_name, last_name, birthday_date, sex, pic_square, current_location, hometown_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 ORDER BY birthday_date";
$year =array();
$prm = array(
'method' => 'fql.query',
'query' => $query,
'callback' => ''
);
$friends = $facebook->api($prm);
for($m = 1;$m <= 12;$m++){
$dm = mktime(0,0,0,$m,26);
$dm = date("M", $dm);
$year[] = $dm;
for($d = 1;$d <= 31;$d++){
$a2 = array($d => array());
$a3 = $out[$dm];
array_push($out,array($dm => array($d => "")));
}
}
PS:我希望能够在每月的每月以每月的方式代表生日。 谢谢。
I'm a newbie in PHP programming. I use a FQL query to get birthdays of all user's friends.
But I want to sort the users according to month and day. Can this be possible in multidimensional arrays? I want:
$year = array('jan' => array('1' => array(data returned by fql query), '2' => array(data returned by fql query),..etc), 'feb' => array('1' => array(data returned by fql query)), 'mar' => array(), etc);
Is it possible?
My code so far:
$query = "SELECT uid, first_name, last_name, birthday_date, sex, pic_square, current_location, hometown_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 ORDER BY birthday_date";
$year =array();
$prm = array(
'method' => 'fql.query',
'query' => $query,
'callback' => ''
);
$friends = $facebook->api($prm);
for($m = 1;$m <= 12;$m++){
$dm = mktime(0,0,0,$m,26);
$dm = date("M", $dm);
$year[] = $dm;
for($d = 1;$d <= 31;$d++){
$a2 = array($d => array());
$a3 = $out[$dm];
array_push($out,array($dm => array($d => "")));
}
}
PS: I want to be able to represent birthdays in each month in a div, order by day of month.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
multi_sort($myArray[index], SORT_NUMERIC, SORT_ASC) 就是您正在寻找的,并且您可以摆脱嵌套的 for 循环。传递要排序的数组和索引,按数字排序,并根据您的需要以 SORT_ASC 或 SORT_DESC 形式排序。您可能需要先从日期中删除破折号或斜杠,然后进行实验并找出答案。
这是 PHP 手册页。 http://php.net/manual/en/function.array-multisort.php
multi_sort($myArray[index], SORT_NUMERIC, SORT_ASC) is what you are looking for, and you can get rid of the nested for loops. pass the array and index to be sorted by, sort numerically, and in SORT_ASC, or SORT_DESC depending on what you want. You may need to removed dashes or slashes from the dates first, experiment and find out.
Here is the PHP man page. http://php.net/manual/en/function.array-multisort.php
或者,您可以将日/月设置为数组键并基于排序:
请注意,如上所述,facebook 允许您在其端进行排序,因此最好让他们完成这项工作。在某些情况下,查询后排序非常有用,这通常是我喜欢的方式。
Or you could make the day/month an array key and sort based one that:
Note that as mentioned, facebook allows you do do the sorting on their end, so it's best to let them do the work. There are some cases where post-query sorting is very useful, and this is generally how I like to do it.