PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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


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
)



ASK A QUESTION

More arrays PHP Questions

OK I've been trying to echo out the arrays "$people and $other people" using the for-each method in alphabetical order. but when i see what this displays it does it in some other order. THIS IS THE CODE PHP Ch8 Lab

How do I count the number of times a value appears in an array?

How do I reverse sort the members of an array?

How do I reverse the order of the elements in an array?

when i fetch the record in the database but they skip first record in the database



Custom Search