json格式问题

array

(

[0] => array

(

[0] => https://adc.cn/public/image/1.jpg

[1] => http://www.adc.com/

)

[1] => array

(

[0] => https://adc.cn/public/image/2.jpg

[1] => http://www.adc.com/

)

[2] => array

(

[0] => https://adc.cn/public/image/3.jpg

[1] => http://www.adc.com/

)

)

如何json输出

{“link”: {

“rel”: “https://adc.cn/public/image/3.jpg”,

“href”: ” http://www.adc.com/”,

}}

回复讨论(解决方案)

只要最后一个?
$a = array(
array(
‘https://adc.cn/public/image/1.jpg’,
‘http://www.adc.com/’,
),
array(
‘https://adc.cn/public/image/2.jpg’,
‘http://www.adc.com/’,
),
array(
‘https://adc.cn/public/image/3.jpg’,
‘http://www.adc.com/’,
),
);
$r = array(‘link’ => array_combine(array(‘rel’, ‘href’), array_pop($a)));
echo json_encode($r, json_unescaped_slashes);

{“link”:{“rel”:”https://adc.cn/public/image/3.jpg”,”href”:”http://www.adc.com/”}}

Posted in 未分类

发表评论