Chaitanya Lakshmi
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook

I want to invert my array, can I do this?

4/10/2012

0 Comments

 
The answer is yes, but it depends what you mean by invert. On clarification you wanted to amend the array so that the values and keys switched over, and this is done through using the function array_flip, like this:

<?php 

$values = array("Fred","Bob","George"); 
print_r($values); 

$values = array_flip($values); 
print_r($values); 
?> 

Which returns:

Array
(
[0] => Fred
[1] => Bob
[2] => George
)
Array
(
[Fred] => 0
[Bob] => 1
[George] => 2
)
0 Comments



Leave a Reply.

    Archives

    April 2012
    March 2012
    February 2012

    Categor

    All
    Ajax
    Api
    Cross Site Scripting
    Css
    Curl
    Design Patterns
    Drupal
    Exception Handling
    Htaccess
    Html
    Javascript
    Jquery
    Json
    Linux
    Mysql
    Oops
    Php
    Regular Expressions
    Web 2.0
    Webservices
    Wordpress
    Xhtml

    RSS Feed

Powered by Create your own unique website with customizable templates.