2017-06-07 3 views
-1

私はJSONに変換する必要があるget_post_metaから生成されたデータを持っています。生成された配列は以下の通りである:JSONへのget_post_meta()

Array 
(
    [0] => Array 
     (
      [0] => Array 
       (
        [0] => Array 
         (
          [rate] => 5 
          [review] => Array 
           (
            [content] => Test Review 
            [custom_field_1] => Azman Ishak 
            [custom_field_2] => Selagnor 
            [date] => 2017-06-06 , 15:06 
            [title] => 
            [status] => publish 
            [weight] => 5 
           ) 

          [user] => Array 
           (
            [name] => ebeneadmin 
            [email] => [email protected] 
            [id] => 1 
            [ip] => 115.135.10.5 
           ) 

         ) 

       ) 

     ) 

    [1] => Array 
     (
      [0] => Array 
       (
        [0] => Array 
         (
          [rate] => 4 
          [review] => Array 
           (
            [content] => Test review 2 
            [custom_field_1] => Azman 
            [custom_field_2] => Beranang 
            [date] => 2017-06-06 , 16:01 
            [title] => 
            [status] => publish 
            [weight] => 5 
           ) 

          [user] => Array 
           (
            [name] => Azman Ishak 
            [email] => [email protected] 
            [id] => 
            [ip] => 115.135.10.5 
           ) 

         ) 

       ) 

     ) 

    [2] => Array 
     (
      [0] => Array 
       (
       ) 

     ) 

) 

Iは、上記アレイから取得する必要がある値である:

  • コンテンツ
  • custom_field_1
  • custom_field_2
  • 日付

    1. レート
    2. タイトル
    3. ステータス

    このデータはJSONに変換する必要があります。

  • +1

    こんにちは、SOへようこそ。ここでは、コードを書くのではなく、特定のプログラミング上の問題についてお手伝いします。あなたが2日間立ち往生して以来、これまでに何を試してみたか、私たちとあなたの考えを分かち合いましょう。私はあなたが助けを受けるだろうと確信しています。あなたの間違いから学ぶことができ、単純にコピー+貼り付けをするつもりはありません。 – Twinfriends

    答えて

    0

    これを試してみてください:

    をごget_post_metaが、それはあなたの結果は

    <?php 
    $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); 
    
    echo json_encode($arr); 
    ?> 
    

    出力されるようになりますjson_encode();

    となる変換:

    {"a":1,"b":2,"c":3,"d":4,"e":5}