[英]PHP - printing out an array does not seem to produce what I intended
我正在使用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 ) ) )
看来这与我原本打算的格式完全不同。 还是我在某种程度上不正确?
谢谢,亚历克斯
似乎您忘记了对$ message变量进行json_encode。
<?php echo json_encode($message); ?>
您需要执行以下操作: echo json_encode($message);
print_r($message);
只是转储数组的内容,用于调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.