I am trying to sort a list of partners either by Place (alphabetically) or german postcode.
The code I have come up with works fine locally using XAMPP but as soon as I upload it I get the following error:
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /mnt/am2/06/739/00000010/htdocs/fmxf/sortCA.php on line 17
as you can see at http://www.rattenfaenger-hameln.de/fmxf/sortCA.php
I have tried the same script on 3 different webservers, to no avail.
Line 17 reads
foreach($arr as $k => &$e){
and is in a function. I am calling this function by using create_function.
The full script looks like this:
<form name="form1" method="post" action="<? $_SERVER['PHP_SELF']?>">
<input type="hidden" name="stage" value="process">
<p>
<select name="sorter" size="1" id="sorter">
<option value="" selected>Sortiere nach...</option>
<option value="name">Ort</option>
<option value="plz">PLZ</option>
<option value="strasse">Straße</option>
</select>
</p>
<input type="submit" name="Submit" value="Senden">
</form>
<?
//--------------The function
function sortByFunc(&$arr, $func){
echo "calling now<br><br>";
$tmpArr = array();
foreach($arr as $k => &$e){
$tmpArr[] = array('f' => $func($e), 'k' => $k, 'e' =>&$e);
}
sort($tmpArr);
$arr = array();
foreach($tmpArr as &$fke) {
$arr[$fke['k']] = &$fke['e'];
}
}
//-----------------The array I am trying to sort
$arr = array(
1 => array('name'=>"Dresden", 'plz'=>"01307", 'strasse'=>"Dürerstraße 49", 'fon'=>"+49 (0351) 44 967 12", 'link'=>"http://www.car-akustik.de/dresden/stand_dr.htm"),
2 => array('name'=>"Riesa", 'plz'=>"01591", 'strasse'=>"Stahlwerker Straße 2", 'fon'=>"+49 (03525) 73 44 69", 'link'=>"http://www.car-akustik.de/riesa/stand_rie.htm"),
3 => array('name'=>"Halle/Saale", 'plz'=>"06126", 'strasse'=>"Nietlebener Straße 11", 'fon'=>"+49 (0345) 55 122 47", 'link'=>"http://www.car-akustik.de/halle/stand_ha.htm"),
4 => array('name'=>"Gera", 'plz'=>"07548", 'strasse'=>"Hofer Str. 2", 'fon'=>"+49 (0365) 80 074 12", 'link'=>"http://www.car-akustik.de/gera/stand_gera.htm"),
5 => array('name'=>"Zwickau", 'plz'=>"08064", 'strasse'=>"Lengenfelder Str. 6", 'fon'=>"+49 (0375) 77 888 97", 'link'=>"http://www.car-akustik.de/zwickau/stand_zwickau.htm"),
6 => array('name'=>"Rathenow", 'plz'=>"14712", 'strasse'=>"Sandweg 11", 'fon'=>"+49 (03385) 54 93 15", 'link'=>"http://www.car-akustik.de/rathenow/stand_rathenow.htm"),
7 => array('name'=>"Mainz-Kastel", 'plz'=>"55252", 'strasse'=>"Philippsring 18", 'fon'=>"+49 (06134) 46 64", 'link'=>"http://www.car-akustik.de/mainz/stand_mainz.htm"),
8 => array('name'=>"Stuttgart-Bad Cannstadt", 'plz'=>"70374", 'strasse'=>"Hofener Str. 140", 'fon'=>"+49 (0711) 55 905 20", 'link'=>"http://www.car-akustik.de/stuttgart/stand_s-badcannstatt.htm"),
9 => array('name'=>"Rosenheim", 'plz'=>"83026", 'strasse'=>"Klepperstraße 28", 'fon'=>"+49 (08031) 26 86 66", 'link'=>"http://www.car-akustik.de/rosenheim/stand_rosen.htm"),
);
//-------------------------------assigning the value from my dropdown to a variable
$criteria=$_POST['sorter'];
echo "Suche nach ".$criteria. "<br>";
//---------------------------Call the function
sortByFunc($arr,create_function('$element','return $element['.$criteria.'];'));
//Output the newly sorted array in a table
echo '<table border="1" width=<"100%">';
foreach($arr as $key => $val) {
echo "<tr><td><a href=". $val['link']." target='_blank'><b>car akustik ". $val['name'] ."</b></a></br>".$val['strasse']."<br/ >". $val['plz'] ." ".$val['name']."<br />".$val['fon']."</td></tr>";
}
echo '</table>';
?>
If anyone has any idea as to why it works locally but not online I would be very grateful. I changed permissions on the script.
Thanks for any help,
FG