array_search function bugged?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following code does not produce the correct results (for my purposes):

function code($str, $match, $formula)
 {
for($i = 0; $i < count($str); $i++)
 {
$formula[$i] = array_search($str[$i], $str);// <<======|| no bueno
  //print $formula[$i]; not right
 if($formula[$i] < $i)
  {$str[$i] = '';}
  }
 //print'<br>'; //----- etc (lots more code)------->

The code takes a string of ascii letters forming a word and is supposed to create a list of indexes in the proper sequence for reconstructing the word. The object of the code in context is to take any word and create an array of unique letters with no repeats so that gd can be used to produce images of each letter. The letters are then reassembled in the browser to form the word. The $formula above is supposed to tell the browser in what sequence to display each letter, including using the same letter image in repeat locations. For this it fails miserably.

These are the results of test steps:

dissatisfaction (the test word)
Processed input string:   dissatisfaction (code output at key step to verify) at creation of formula:    012245128410511314 (formula sampled at ' no bueno' line in code) from browser source array:    012245128410511314 (formula pasted from browser javascript source)

The letter images spell out:
disstfisntidfiiait which is in accordance with the formula as far as I can tell.

Is this a bug or am I misusing this function?
server platform: FreeBSD v6.0
Apache version: 1.3.34
php version: 5.1.2

There is one other weakness I've discovered, if arrays are created in one code sequence and are called to print in loops more than once or processed in different code sections. The second time the same array is called it has significantly degraded, loosing values from index positions.

the seems to be no bug report accommodation in the php.net site so I'm posting here.
Thanks in advance,
JK

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux