• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Looking for Function that converts Associative Array to Index Array

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
minichicken
Asked:
minichicken
1 Solution
 
BatalfCommented:
<?

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
 
Marcus BointonCommented:
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
 
minichickenAuthor Commented:
Thanks Squinky

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

Thanks for the reminder....
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now