nit, fyi  it is more efficient to do: 
for ($i = 1, $j = count($p12n['searchorder']); $i <= $j; $i++) 
It avoids doing count() on each loop iteration, not a problem for small sets as data.