I am new to PHP and trying to better understand the wordpress source code.
In my travels I have come across the following line of code…
$lastc = $data[$length-1];
Can anyone tell me what the purpose of the $length-1 is within the data array?
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.
If we have an array:
Then the
$length, beingcount($arr), is 5. $data[$length – 1] is the last element (fourth index).However, you’re right to note that this reads terribly. That’s why the developers should probably have just gone with:
Which returns the last element of an array.
If it is a string, they should use:
Which would return the last character of the string.