dink87522 Posted August 16, 2009 Share Posted August 16, 2009 <?php // FUNCTIONS function stat_01($stat_01_handle, $answer_result){ global $stat_01_handle, $answer_result; echo("<br /> stat_01_handle: $stat_01_handle"); echo("<br /> answer_result: $answer_result <p>"); $stat_01_file = "statistics01.txt"; $stat_01 = fopen($stat_01_file, "r"); $stat_01_data = fread($stat_01, filesize($stat_01_file)); fclose($stat_01); $stat_01 = fopen($stat_01_file, "w"); $stat_01_raw = explode("h", $stat_01_data); [b]print_r($stat_01_data);[/b] echo ("<p>Data: ".$stat_01_raw[$stat_01_handle]); $stat_01_temp = $stat_01_raw[$stat_01_handle]; $stat_01_pieces = explode(",", $stat_01_temp); echo("<p> Exploded pieces: ".$stat_01_pieces[0]); // $stat_01_pieces[1] = question/array handle echo("<p> Exploded pieces: ".$stat_01_pieces[1]); // $stat_01_pieces[1] = number of times correct echo("<p> Exploded pieces: ".$stat_01_pieces[2]); // $stat_01_pieces[2] = number of times incorrect if ($answer_result == 1){ // User answered the question correctly $stat_01_pieces[1] = ($stat_01_pieces[1] + 1); // Adds 1 to the correct tally statistic for that question }else{ $stat_01_pieces[2] = ($stat_01_pieces[2] + 1); // Adds 1 to the incorrect tally statistic for that question } //$a = "h".$stat_01_pieces[0].",".$stat_01_pieces[1].",".$stat_01_pieces[2]; //$stat_01_data[$stat_01_handle] = $a; [b]print_r($stat_01_data);[/b] echo("A: ".$a); echo("SH: ".$stat_01_raw[$stat_01_handle]); for fwrite($stat_01, $stat_01_raw); fclose($stat_01); } ?> The data is in the first array when I print it. However by the end of the function it is no longer in that array (I need it be be, while I have changed on of the contents of one of the array values). When I try to print the array at the end the data is not in an array, why??? How can I achieve what I mentioned above (change the contents of one of the array values). Thanks Link to comment https://forums.phpfreaks.com/topic/170476-solved-arrays/ Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 If you are getting the $variables by global $stat_01_handle, $answer_result; Why are sending them again to the function? : function stat_01($stat_01_handle, $answer_result) remove the function parameters: function stat_01() But still use the globals: function stat_01() { global $stat_01_handle, $answer_result; Link to comment https://forums.phpfreaks.com/topic/170476-solved-arrays/#findComment-899250 Share on other sites More sharing options...
dink87522 Posted August 16, 2009 Author Share Posted August 16, 2009 I done that, although the code does not work still. Link to comment https://forums.phpfreaks.com/topic/170476-solved-arrays/#findComment-899313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.