?
Solved

Looking for Function that converts Associative Array to Index Array

Posted on 2005-03-14
3
Medium Priority
?
231 Views
Last Modified: 2008-03-06
Hi

I am looking for a Function that converts Associative Array to Index Array.

For example:

From this:
Array ([one] => "value1", [two] => "value2", [three] => "value3");

To this:
Array([0] => "value1, [1] => "value2", [3] => "value3");

Thanks....
0
Comment
Question by:minichicken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13534279
<?

function convertArray($inputArray){
    $returnArray = array();
    foreach ($inputArray as $value) {
       $returnArray[] = $value;
    }
   
    return $returnArray;

   
   
}

$array['key1'] = "value";
$array['key2'] = "val2";
$array['key3'] = "val3";
$array['key4'] = "val4";

$newArray = convertArray($array);

for($no=0;$no<count($newArray);$no++){
    echo $newArray[$no]."<br>";
}
?>
0
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 2000 total points
ID: 13534329
This is effectively what array_values does, by simply discarding associative keys:

http://www.php.net/manual/en/function.array-values.php

Unless you're expecting it to interpret 'three' as index 3. I think your example is slightly wrong, I'm guessing it should be:

To this:
Array([0] => "value1, [1] => "value2", [2] => "value3");
0
 
LVL 12

Author Comment

by:minichicken
ID: 13534418
Thanks Squinky

I was clearly NOT thinking....
I have used that function million times...

Thanks for the reminder....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question