我需要使用json_encode()
:
{
"Image":"wordpress",
"Env" :[
"VIRTUAL_HOST=domain.com"
],
"ExposedPorts":{
"8080":"80"
}
}
我被困在ExposedPorts,请帮忙。这是我的php数组,但它不起作用:
[
'Image'=> 'wordpress',
'Env' => [
"VIRTUAL_HOST=domain.com"
],
'ExposedPorts'=>json_encode(["8080"=>"80"],JSON_FORCE_OBJECT)
]
答案 0 :(得分:1)
为什么不像这样json_encode整个数组,
<?php
$array = array(
"Image" =>"wordpress",
"Env" =>
["VIRTUAL_HOST=domain.com"
],
"ExposedPorts"=>
array("8080"=>"80"));
echo json_encode($array);
输出:
{"Image":"wordpress","Env":["VIRTUAL_HOST=domain.com"],"ExposedPorts":{"8080":"80"}}