简体   繁体   English

获取最后一个URL

[英]Get last item URL

I have a data in following JSON sort of format in which I am trying to only get the very last URL which in my following example is https://lastexample.com/images/I/4162nAIaRCL.jpg . 我有以下JSON格式的数据,我尝试只获取最后一个URL,在下面的示例中为https://lastexample.com/images/I/4162nAIaRCL.jpg Is there an easy way I can retrieve this via PHP? 有没有一种简便的方法可以通过PHP检索此信息?

{"https://example.com/images/I/4162nAIaRCL._SX425_.jpg":[425,425],
"https://example.com/images/I/4162nAIaRCL._SY355_.jpg":[355,355],
"https://example.com/images/I/4162nAIaRCL._SX466_.jpg":[466,466],
"https://example.com/images/I/4162nAIaRCL._SY450_.jpg":[450,450],
"https://lastexample.com/images/I/4162nAIaRCL.jpg":[500,500]}

Try this : 尝试这个 :

<?php 
$json = '{
    "https://example.com/images/I/4162nAIaRCL._SX425_.jpg":[425,425],
    "https://example.com/images/I/4162nAIaRCL._SY355_.jpg":[355,355],
    "https://example.com/images/I/4162nAIaRCL._SX466_.jpg":[466,466],
    "https://example.com/images/I/4162nAIaRCL._SY450_.jpg":[450,450],
    "https://lastexample.com/images/I/4162nAIaRCL.jpg":[500,500]
}';


$arr = json_decode($json,true);
$arrkeys = array_keys($arr);
$lastkey = end($arrkeys);
echo $lastkey; 
?>

Try, decode it into an array ( json_decode ) then get the keys ( array_keys ), then the last entry ( end / max ). 尝试将其解码为数组( json_decode ),然后获取键( array_keys ),然后获取最后一个条目( end / max )。

<?php
$json = '{
    "https://example.com/images/I/4162nAIaRCL._SX425_.jpg": [425, 425],
    "https://example.com/images/I/4162nAIaRCL._SY355_.jpg": [355, 355],
    "https://example.com/images/I/4162nAIaRCL._SX466_.jpg": [466, 466],
    "https://example.com/images/I/4162nAIaRCL._SY450_.jpg": [450, 450],
    "https://lastexample.com/images/I/4162nAIaRCL.jpg": [500, 500]
}';

$array = json_decode($json, true);

$keys = array_keys($array);

echo end($keys); // https://lastexample.com/images/I/4162nAIaRCL.jpg

https://3v4l.org/MLbdt https://3v4l.org/MLbdt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM