[英]PHP - printing out an array does not seem to produce what I intended
I am using PHP and trying to create an array that looks something like this: 我正在使用PHP并试图创建一个看起来像这样的数组:
{
"aps" : {
"alert" : "Hey"
},
"custom_control" : {
"type" : "topic_comment",
"object":{
"topic_id":"123",
"topic_section":"test"
"plan_id":"456"
}
}
}
The code I have is: 我的代码是:
<?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);
?>
but what is printed out is this: 但是打印出来的是这样的:
Array ( [aps] => Array ( [alert] => hey ) [custom_control] => Array ( [type] => topic_comment [object] => Array ( [topic_id] => 123 [topic_section] => abc [plan_id] => 456 ) ) )
It seems like this is a totally different format from what I had intendd. 看来这与我原本打算的格式完全不同。 Or am I incorrect in some way?
还是我在某种程度上不正确?
Thanks, Alex 谢谢,亚历克斯
似乎您忘记了对$ message变量进行json_encode。
<?php echo json_encode($message); ?>
You need to do this: echo json_encode($message);
您需要执行以下操作:
echo json_encode($message);
print_r($message);
just dumps the contents of the array, used it for debugging. 只是转储数组的内容,用于调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.