I have this array from an AJAX request:
array (
[0] => 'lat,long@id_1'
[1] => 'lat,long@id_2'
[2] => 'lat,long@id_3'
)
The problem here is I'm not gonna have always a 'correct-ordered' array like that, so it may look like this one:
array (
[0] => 'lat,long@id_1'
[1] => 'lat,long@id_2'
[2] => 'lat,long@id_3'
[3] => 'lat,long@id_1'
[4] => 'lat,long@id_3'
[5] => 'lat,long@id_2'
)
I need to get the last array value of every id_X (currently only 3 ids):
array (
[3] => 'lat,long@id_1'
[4] => 'lat,long@id_3'
[5] => 'lat,long@id_2'
)
How can I find each last value of that array based on partial string (id_X)?
3,4, and5in the result?explode()to split the string at@. Then create an associative array whose keys areid_X. You'll get just one entry for eachid_X.