I have a file process.php that contains form data and puts it to a serialized array, which then is written to a flat file. After writing the data and unserializing the array on the other page, I need to sort the array by number values. The problem is that after serializing the sort method does not work. If someone who knows better would point out the solution, I would appreciate it. Thanks.
Here's the process.php code:
and here's the php code of the page which loads the data from flat file:
Here's the process.php code:
Code:
<?php header ("Location: http://example.com"); $Species = $_POST["kalalaji"]; $Weight = $_POST["paino"]; $Name = $_POST["nimi"]; $Check = preg_match("/[A-Za-z+إؤضهنِ+, -]/i", $Weight); $Arr = array($Name => $Weight); $Ser_Arr = serialize($Arr); if($Species == "Ahven" and $Check == FALSE and $Species != "") { $File = "data.php"; $Handle = fopen($File, "a+"); fwrite($Handle, $Ser_Arr."\n"); fclose($Handle); } else { $File = "data.php"; $Handle = fopen($File, "r"); fclose($Handle); } ?>
Code:
<?php $File = file_get_contents("data.php"); $Unser_File = unserialize($File); $Values = array_values($Unser_File); rsort($Values); echo $Values[0]; // The result is always the first item of the array. ?>
Comment