将PHP数组转换为Json包含对象
我需要使用将PHP数组转换为Json包含对象,php,arrays,json,Php,Arrays,Json,我需要使用json\u encode() 我在暴露端口卡住了,请帮忙。这是我的php数组,但不起作用: [ 'Image'=> 'wordpress', 'Env' => [ "VIRTUAL_HOST=domain.com" ], 'ExposedPorts'=>json_encode(["8080"=>"80"],JSON_FORCE_OBJECT) ] 为什么不这样对整个数组进
json\u encode()
我在暴露端口卡住了,请帮忙。这是我的php数组,但不起作用:
[
'Image'=> 'wordpress',
'Env' => [
"VIRTUAL_HOST=domain.com"
],
'ExposedPorts'=>json_encode(["8080"=>"80"],JSON_FORCE_OBJECT)
]
为什么不这样对整个数组进行json_编码
<?php
$array = array(
"Image" =>"wordpress",
"Env" =>
["VIRTUAL_HOST=domain.com"
],
"ExposedPorts"=>
array("8080"=>"80"));
echo json_encode($array);
问题是什么?你的php数组在哪里?你在哪里卡住了?你说的“卡住”是什么意思?你能解释一下吗?我不知道如何从php在ExposedPorts中创建json对象array@spqa请提供您的php数组
<?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"}}