簡體   English   中英

獲取最后一個URL

[英]Get last item URL

我有以下JSON格式的數據,我嘗試只獲取最后一個URL,在下面的示例中為https://lastexample.com/images/I/4162nAIaRCL.jpg 有沒有一種簡便的方法可以通過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]}

嘗試這個 :

<?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; 
?>

嘗試將其解碼為數組( 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM