I have an array that i want to invert how do i do this?
Share
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.
This really depends on whether you mean invert or reverse?
If you want to invert your keys with the values then take a look at
array_fliphttp://www.php.net/manual/en/function.array-flip.phpOutput:
if you want to reverse your array then use
array_reversehttp://php.net/manual/en/function.array-reverse.phpOutput:
You may also want to reverse the array but key the values assigned to their keys in that case you will want
$values = array_reverse($values, true);