以一致的方式构建“功能”的组合

时间:2011-12-20 03:25:18

标签: php

我的应用程序需要使用下面代码的一堆变体。下面的代码大约有六到七种变体,但我在组织它们时遇到了麻烦 起初,我创建了一个类并将它们分成函数但由于某种原因所有函数都停止工作。只是浏览下面的代码,您是否看到了组织这样的事情的好方法?

try{
    $fql = "select uid,name,education from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
    $param  =   array(
        'method'    => 'fql.query',
        'query'     => $fql,
        'callback'  => ''
    );
    $fqlResult   =   $facebook->api($param);
}
catch(Exception $o){
    d($o);
}

$friends = $fqlResult;
$friends_BA = array();

foreach ($friends as $friend) {
    $isBA = false;
    if (is_array($friend['education'])) {
        foreach ($friend['education'] as $school) {
            if (isset($school['concentration'])) {
                foreach ($school['concentration'] as $concentration) {
                    if (strpos(strtolower($concentration['name']), 'business') !== false) {
                        $friends_BA[] = $friend['name'];
                        continue 3; // skip to the next friend
                    }
                }
            }
        }
    }
}

d($friends_BA);

1 个答案:

答案 0 :(得分:0)

  function getLocalFriends () {
             $config = array(
             'appId' => 'XXXXXXXXXX',
             'secret' => 'XXXXXXXXXXX',
             );
             $facebook = new Facebook($config);
             $user_id = $facebook->getUser();
             try {
             $fql    =   "select name,current_location from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
             $param  =   array(
             'method'    => 'fql.query',
             'query'     => $fql,
             'callback'  => ''
             );
             $fqlResult   =   $facebook->api($param);
             }
                 catch(Exception $o){
             d($o);
             }

             $friends = $fqlResult;
             $friends_BA = array();
             foreach ($friends as $friend) {
               $isBA = false;
               if (is_array($friend['current_location'])) {
                  $lowerName = strtolower($friend['current_location']['city']);
                      if (strpos($lowerName, 'orlando') !== false || strpos($lowerName, 'altamonte springs') !== false) {
                      $friends_BA[] = $friend['name'];
            }
         }
       }
             echo '<pre>';
             print_r($friends_BA);
             echo '</pre>';
}
相关问题