0

This is the result of my array:

array(3) {
  [968]=>
  string(12) "TRALALAA0"
  [918]=>
  string(23) "TRALALAA1"
  [912]=>
  string(66) "TRALALAA2"
}

I want that output would be:

 array(3) {
      ['TRALALAA0']=>
      string(12) "968"
      ['TRALALAA1']=>
      string(23) "918"
      ['TRALALAA0']=>
      string(66) "912"
    }

Is there a function to do that stuff in PHP ?

1
  • 2
    Using the array_flip() function Commented Jul 29, 2014 at 7:22

4 Answers 4

6
$array = array_flip($array);

This function flips the keys with the values

Sign up to request clarification or add additional context in comments.

Comments

2

You can use array_flip for this.

$valsAsKeys = array_flip($array);

Comments

2

the function is called array_flip

Comments

2

You are looking for array_flip()

$arr = array_flip($arr);

More details here: http://php.net/manual/en/function.array-flip.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.