S1mba Posted October 31, 2012 Share Posted October 31, 2012 (edited) Hi, I have multiple txt files and I would like to loop them all the the same time Since foreach works with only one array, how do i loop and echo 3 arrays ($handle, $handle2 and $handle_date)? Thanks if(isset($_POST['name'])AND(isset($_POST['msg']))){ $name = $_POST['name']; $msg = $_POST['msg']; if(!empty($name)AND(!empty($msg))) { $handle = fopen('1all_names.txt', 'a'); fwrite($handle, $name."\n"); fclose($handle); $handle2 = fopen('1msg.txt', 'a'); fwrite($handle2, $msg."\n"); fclose($handle2); $handle_date = fopen('1date.txt', 'a'); fwrite($handle_date, $date."\n"); fclose($handle_date); Edited October 31, 2012 by S1mba Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 31, 2012 Share Posted October 31, 2012 None of those variables are arrays. I'm really not sure what you are doing as it looks like the code is simply reading the data from one file and writing it into another. Are you wanting to combine the data from the three files into a single file? If so, are the files structured in such a way that there is a one-to-one correspondence between the data in the three files? Quote Link to comment Share on other sites More sharing options...
S1mba Posted October 31, 2012 Author Share Posted October 31, 2012 (edited) After a little bit of research figured out that I have forgotten to convert them to arrays $readin_name = file('1_names.txt'); $readin_msg = file('1_msg.txt'); $readin_date = file('1_date.txt'); $readin_date = array_reverse($readin_date); $readin_msg = array_reverse($readin_msg); $readin_name = array_reverse($readin_name); $count = count($readin_date); for ($i=0; $count > $i; $i++){ echo $i.' - '.'<strong>'.$readin_name[$i].'</strong>'.' wrote '.$readin_msg[$i].' on the date '.$readin_date[$i].'<br>'; } solved. Edited October 31, 2012 by S1mba 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.