部分字符串我有一個AJAX請求此陣:發現裏面陣列
array (
[0] => 'lat,[email protected]_1'
[1] => 'lat,[email protected]_2'
[2] => 'lat,[email protected]_3'
)
這裏的問題是我不會總是那樣的「正確排序」陣列,所以它可能看起來像這一個:
array (
[0] => 'lat,[email protected]_1'
[1] => 'lat,[email protected]_2'
[2] => 'lat,[email protected]_3'
[3] => 'lat,[email protected]_1'
[4] => 'lat,[email protected]_3'
[5] => 'lat,[email protected]_2'
)
我需要讓每一個id_X
(目前只有3 IDS)的最後一個數組值:
array (
[3] => 'lat,[email protected]_1'
[4] => 'lat,[email protected]_3'
[5] => 'lat,[email protected]_2'
)
如何根據部分字符串(id_X
)找到該數組的每個最後一個值?
你需要索引在結果中是「3」,「4」還是「5」? – Barmar
使用'explode()'將字符串拆分成'@'。然後創建一個關鍵字爲'id_X'的關聯數組。每個'id_X'只會有一個條目。 – Barmar
@barmar不,只是值是好的。 –