Please help me to translate this pseudo-code to real php code:
foreach ($arr as $k => $v)
if ( THIS IS NOT THE LAST ELEMENT IN THE ARRAY)
doSomething();
Edit: the array may have numerical or string keys
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
you can use PHP’s end()
Update1
as pointed out by @Mijoja the above could will have problem if you have same value multiple times in array. below is the fix for it.
Update2
I found solution by @onteria_ to be better then what i have answered since it does not modify arrays internal pointer, i am updating the answer to match his answer.
Thank you @onteria_
Update3
As pointed by @CGundlach PHP 7.3 introduced
array_key_lastwhich seems much better option if you are using PHP >= 7.3