Hi all
Here is an update on my problem reported with the array_search function.
to those who directed me to the bug report page, thanks.
There are a number of reports specific to this function. Maybe event
someone else has written a fix.
here is my solution to my problem.
The following code* was developed and finalized by J.E.Killen 3/2006
* accept of course for array_search() itself.
function word_wise(array $input, int $what) //returns an array
{$str = array();
$stra = array();
$str = str_split($input); //turns string into
array
$stra = $str; // saves a copy for final
reconcilliation
$tmp = ''; // used to hold and transfer values
$final = array(); // ***THE WHOLE POINT****
$reduced = array(); // reduction array
$formula = array(); // interum array
$output = array(); // test output.
for($i = 0; $i < count($str); $i++)
{$formula[$i] = array_search($str[$i],
$str);
if($formula[$i] < $i) // use of $formula
{$str[$i] = '';} // repeats eliminated from $str
}; // if $i is greater than formula[$i], formula[$i] is a repeat.
for($i = 0; $i < count($str); $i++)
{if($str[$i] != '') // looks for empty
strings in $str
{
array_push($reduced, $str[$i]); //
fills $reduced with
// non
empty $str items
// to
produce an array of
// all
unique letters
}
};
for($i = 0; $i < count($stra); $i++)
{for($j = 0; $j < count($reduced); $j++)
{
if($stra[$i] == $reduced[$j])//produces
the final formula for
{$final[$i] = $j; } //
reconstruction of the word.
}
}
for($i = 0; $i < count($final); $i++)
{ $tmp = $final[$i];
$output[$i] = $reduced[$tmp]; //test run
reconstructs word from $final and $reduced.
}
switch($what) //options to chose what to return
{case 1:
return $reduced; //reduction to all unique
letters
break;
case 2:
return $stra; //original
break;
case 3:
return $final; // reconstruction formula
break;
case 4:
return $output; //test
break;
}
} // end word_wise()
Just want to return something to the php community
Jeff K
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php