$array = array_values($array);
<?php
$a = array("foo", "bar");
$aa = array();
foreach ($a as $idx => $val) {
$aa[$val] = $idx + 1;
}
print_r($aa);
?>
<?php
$a = array("foo", "bar");
$aa = array_flip($a);
print_r($aa);
?>
Array
(
[foo] => 1
[bar] => 2
)
Array
(
[foo] => 0
[bar] => 1
)