[Typo3-dev] Splitting array acording to alphabet

Bernhard Kraft kraftb at kraftb.at
Fri Jun 17 16:08:36 CEST 2005


Well. It's the supstr statement. Most propbably the guy you asked for
help doesn't know PHP as good as it seemd to ... (no offense meant !)

Georg Ringer wrote:
>  if(substr($name[nname], 0,1) == substr($az[$x], 0,1) ||
fine. compare first character of $name with first character of $az[$x]

> substr($name[nname], 0,1) == substr($az[$x], 1,2) ||

not fine any more ... compare first character of $name with the SECOND AND THIRD
character of $az[$x] : if ("W" == "VW") -> always false ...

it must be correct:

substr($name[nname], 0,1) == substr($az[$x], 1,1) ||
                                                ^
note the 2 in the second substra has changed to 1. The third parameter of substr is not
until where you want a substring but HOW MANY characters you wont from the given position.

so in the third one we replace the 3 by 1
> substr($name[nname], 0,1) == substr($az[$x], 2,3))
becomes:
 > substr($name[nname], 0,1) == substr($az[$x], 2,1))


And one other thing: I don't really understand what the code should do (I could just extract
that you are using substr false).

If you Want to have an array afterwards which looks like:

Array (
   'ABC' => Array(Array('nname' => 'Atzinger', 'vname' => 'Fritz', 'uid' => 20), Array(....))
   'DEF' => Array(Array('nname' => 'Dante', 'vname' => 'Fritz', 'uid' => 20), Array(....))
    ....
)

then you should use another >less CPU intensive> alogorythm.

Just ask again if you need it ...


greets,
Bernhard





More information about the TYPO3-dev mailing list