Would this code do the trick?
<?
$array = array("amit", "hello", "amit", "world", "hello");
/* Sort into an array */
$i=0;
foreach ($array AS $value){
$result[$value][]=$i;
$i++;
}
/* Dump Result */
echo '<xmp>';
print_r($result);
echo '</xmp><hr>';
/* Display Results */
foreach ($result AS $name=>$var) {
echo $name.' ';
foreach ($var AS $arrayposition) {
echo $arrayposition.', ';
}
echo '';
}
?>
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
Don't do that, there's a built-in PHP function. array_keys($array, "search_key") , that returns an array containing the indices for the searc_key
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268