2013-03-25 46 views
0

我使用PHP,并试图创建一个数组,看起来是这样的:PHP - 打印出数组似乎没有产生什么,我打算

{ 
    "aps" : { 
     "alert" : "Hey" 
    }, 
    "custom_control" : { 
     "type" : "topic_comment", 
     "object":{ 
      "topic_id":"123", 
      "topic_section":"test" 
         "plan_id":"456" 
     } 
    } 
} 

我的代码是:

<?php 
    $message = array(
     "aps" => array(
      "alert" => "hey" 
     ), 
     "custom_control" => array(
      "type" => "topic_comment", 
      "object" => array(
       "topic_id" => "123", 
       "topic_section" => "abc", 
       "plan_id" => "456" 
      ) 
     ) 
    ); 

print_r($message); 
?> 

但什么是打印出来是这样的:

Array ([aps] => Array ([alert] => hey) [custom_control] => Array ([type] => topic_comment [object] => Array ([topic_id] => 123 [topic_section] => abc [plan_id] => 456))) 

看起来这是从我有intendd一个完全不同的格式。或者我在某种程度上不正确?

谢谢, 亚历克斯

回答

5

好像你忘了你的json_encode $消息变量。

<?php echo json_encode($message); ?> 
1

你需要这样做:echo json_encode($message);

print_r($message);只是转储数组的内容,把它用于调试。