jdm95lude Posted March 25, 2008 Share Posted March 25, 2008 I'm doing an assignment. Its a guest book you add you name & email and it saves it to a .txt file you view the guest book the txt file writes to the screen there is a text box that the user can enter in a number that is displayed next to the list of guests and it will delete that name from the txt file. I can't figure it out. Here is a printout of the Assignment http://www.occc.edu/aphilipp/htm_ssp/SSP06_Assignment_Arrays.htm thanks Quote Link to comment Share on other sites More sharing options...
awpti Posted March 25, 2008 Share Posted March 25, 2008 Well, assuming you are storing data as: Person Name,email@address.com ... and then pulling it into an array - the very first item in the list is 0 So, if you want to remove 0.. simple rewrite the data to visitors.txt without entry 0 ex; delete_visitor.php?id=5 <?php $visitors_array = file('visitors.txt'); $i = 0; while($i < count($visitors_array) { if($entry_id != $_GET['visitor_id']) { /// rewrite the file without that 'id' (array key) - in this example, remove key #5 } ++$i; } Concept is there. Work it out. Not that hard. Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted March 25, 2008 Share Posted March 25, 2008 Too complicated, you gotta think more efficiently and look for the right functions. This function will remove a value from array by given key and then reassign numeric keys. <?php function array_remove($array, $key){ unset($array[$key]); return array_values($array); } ?> Quote Link to comment Share on other sites More sharing options...
jdm95lude Posted March 25, 2008 Author Share Posted March 25, 2008 Too complicated, you gotta think more efficiently and look for the right functions. This function will remove a value from array by given key and then reassign numeric keys. <?php function array_remove($array, $key){ unset($array[$key]); return array_values($array); } ?> Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.