2011-02-10 21 views
1

私はステータスオブジェクトを含む配列を持って、これらのステータスのオブジェクトは、オブジェクトのような配列を含み、また、コメントオブジェクトを含むPHP - 使用可能なオブジェクトへのオブジェクトの配列を変換

私の質問は今、私は、配列内のオブジェクトを持っているということですどうやって元に戻しますか?これは後でdbに保存することができるためです。あなたの助けのための

おかげ

アンディ

例えば

Array 
(
    [0] => cStatus Object 
     (
      [statusId:cStatus:private] => 123123123 
      [message:cStatus:private] => powpowpow 
      [updated_time:cStatus:private] => 2011-01-27T15:52:48+0000 
      [likes:cStatus:private] => Array 
       (
       ) 

      [comments:cStatus:private] => Comment Object 
       (
        [commentId:Comment:private] => 123123123 
        [created_time:Comment:private] => 2011-01-30T20:18:50+0000 
        [message:Comment:private] => Kazam 
        [name:Comment:private] => Blue man 
        [createdBy:Comment:private] => 124124 
        [likes:Comment:private] => Array 
         (
         ) 

       ) 

     ) 

    [1] => cStatus Object 
     (
      [statusId:cStatus:private] => 5125125 
      [message:cStatus:private] => Gawdam fruit and fibre is tasty :D 
      [updated_time:cStatus:private] => 2011-01-25T20:21:56+0000 
      [likes:cStatus:private] => Array 
       (
        [0] => Like Object 
         (
          [likeId:Like:private] => 120409086 
          [name:Like:private] => Jt 
         ) 

       ) 

      [comments:cStatus:private] => Array 
       (
       ) 

     ) 

    [2] => cStatus Object 
     (
      [statusId:cStatus:private] => 5215215 
      [message:cStatus:private] => Dear 2 
      [updated_time:cStatus:private] => 2011-01-18T08:28:50+0000 
      [likes:cStatus:private] => Array 
       (
        [0] => Like Object 
         (
          [likeId:Like:private] => 2456 
          [name:Like:private] => Edw2r 
         ) 

        [1] => Like Object 
         (
          [likeId:Like:private] => 2452412 
          [name:Like:private] => aw1 
         ) 

        [2] => Like Object 
         (
          [likeId:Like:private] => 12412411 
          [name:Like:private] => wqw 
         ) 

       ) 

      [comments:cStatus:private] => Array 
       (
       ) 

     ) 
) 
+1

これは配列をオブジェクトに変換していませんか? – BoltClock

+1

:)ちょうど私が$ myObjArray [0] - > methodCall()を行うことができることを知ったので、それをforループで各要素を繰り返してラップします。 – Garbit

+0

ええ、あなたはオブジェクトの配列を持っています。 –

答えて

2

個々のオブジェクトのforeachおよびaccessプロパティを使用して保存できます。すべてのプロパティはプライベートなので、getterメソッドとsetterメソッドを使用していると仮定します。 foreachを使用すると、個々のオブジェクトインスタンスのエイリアスを作成するための "as"キーワードが提供されます。

<?foreach($obj as $status){ 
    $status_text = $status->getMessage(); 
    //save this to database using your favored method; 
    $comments = $status->getComments(); 
    //nest the foreach for all the comments to save them as well, if you like 
    foreach($comments as $comment){ 
    //Save $comment here as well 
    } 
} 
?> 

のパブリックメソッドとプロパティは、データベースに保存するように、簡単なアクションのための個々のイテレータによってアクセスすることができるので、これは、あなたのような複雑なネストされたオブジェクトのために特に便利です。

+0

私は最終的にそれを理解しましたが、あなたはあなたの回答に対して+1の回答を残す必要があります。 – Garbit

関連する問題