2013-04-24 134 views
0

我有一個連接到facebok sdk的函數。PHP找到數組並將其轉換爲變量

此函數回退下面發佈的數組。

我想在該數組和子數組中找到一個特定的變量,並將其存儲到MySQL中。

我需要搜索此索引:[name] => Riad Flam and all sub (ex toke,id,...)並將其存儲到MySQL中。

這是返回數組:

Array 
(
    [data] => Array 
     (
      [0] => Array 
       (
        [category] => Local business 
        [category_list] => Array 
         (
          [0] => Array 
           (
            [id] => 164243073639257 
            [name] => Hotel 
           ) 
         ) 
        [name] => Riad Flam 
        [access_token] => BAAGeBYlwA38BALZAddqsUR2na13zh40E1F7YQMKGiga6fVIzkqBt3RW5r5vTIl3Qnb8lLhZBMk8yNAcRZCp8FDpgGr4ZCagHU1yqJ1w2oUklgAwlZAgJotHYZCJQcw2g1H5uZCdtdhcLwGwLZA2FfEFRGBUgUKvs2a1LJIDFab3vXoS1srbqnZA1cztIH5iyqZB7dEGEXxNEPzMdcvGZCZAw8nuWZCECwkE2WAy0ZD 
        [id] => 124602074303943 
        [perms] => Array 
         (
          [0] => ADMINISTER 
          [1] => EDIT_PROFILE 
          [2] => CREATE_CONTENT 
          [3] => MODERATE_CONTENT 
          [4] => CREATE_ADS 
          [5] => BASIC_ADMIN 
         ) 
       ) 
      [1] => Array 
       (
        [category] => Energy/utility 
        [name] => Ewaa 
        [access_token] => BAAGeBYlwA38BAFWlnftqfUpM0nT3i9OG6BxDHhcoVQEZAsPciUce4zZA2ywWX6LrzlLMXZA24wBRHmG60wZCYSEG0J9kdPTAUnQD9kLMgdDYup1ZBJcji4mzCS2ltJmpGbBCsglcZBwjix8Vl5bhUrOu3o1hZBA6SBsOE9ZC1SZAeJZANdvA0OV2myj4yYEcVvZBinyyzGUhRH3TtYWEb4zfmFfaZAyau9Np2agZD 
        [id] => 239767479474629 
        [perms] => Array 
         (
          [0] => ADMINISTER 
          [1] => EDIT_PROFILE 
          [2] => CREATE_CONTENT 
          [3] => MODERATE_CONTENT 
          [4] => CREATE_ADS 
          [5] => BASIC_ADMIN 
         ) 
       ) 
+0

的foreach()和字符串比較? – 2013-04-24 15:12:48

+1

@RoyalBg:給U男人的帽子......!你理解這個問題嗎? – 2013-04-24 15:14:13

+0

是的,但第二個想法,也許不是,所以,他想從這個'name'所在的同一個鍵檢索數據? – 2013-04-24 15:22:08

回答

0

我想你需要的東西是這樣的:

foreach($return['data'] as $item) { 
    /* PSEUDO CODE: */ 
    $db->insert($item['name']); // just write the insert into function here using $item['name'] as the value to insert 
} 

編輯:

foreach($return['data'] as $item) { 
    /* PSEUDO CODE: */ 
    if($item['name'] == 'insert only this item') { 
     $db->insert($item); 
    } 
} 
+0

感謝這個代碼工作現在的問題是: 我怎麼不能和只存儲前:$ item ['name']其中是=名稱riad flam和所有子密鑰? name,id,token? 如何我可以把代碼放在stackoverfolw響應中... ctrl + k不工作 – gfpl 2013-04-24 15:56:24

+0

@ user2316186檢查我的編輯。 – shadyyx 2013-04-24 15:58:37

+0

HU ..我沒有嘗試這種方式,但對我來說是一個循環...(foreach)和.. nop是好的。是的,保存我的真人感謝! 現在我可以從Facebook存儲令牌長時間 – gfpl 2013-04-24 16:08:33

相關問題