akshay Posted February 23, 2010 Share Posted February 23, 2010 Hello. I need help regarding foreach loop. php.net manual says, foreach means, FOR each element of AN ARRAY, do the following... But, can someone explain me the logic used in these code snipplets (only for foreach statements) : PHP Upload Script: <?php $file_dir="d:/wamp/www/test/files"; foreach($_FILES as $file_name => $file_array) { //what does this mean? ONLY the foreach statement print "Path: ".$file_array['tmp_name']."<br>"; print "Name: ".$file_array['name']."<br>"; print "Type: ".$file_array['type']."<br>"; print "Size: ".$file_array['size']."<br>"; $flnm=$file_array['name']; if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], "$file_dir/$flnm") or die("Error!"); print "Upload Successful!"; } } ?> and another one is simpler (printing date values using php getdate() function) : $date_array=getdate(); foreach($date_array as $key=>$val) { //explain this print "$key = $val<BR>"; } // I simply use this code: print "<BR><BR>The Date is:<br>"; print $date_array['mday']." "; print $date_array['month']." "; print $date_array['weekday']. " "; print $date_array['year']." "; Link to comment https://forums.phpfreaks.com/topic/193047-foreach-loop/ Share on other sites More sharing options...
Wolphie Posted February 23, 2010 Share Posted February 23, 2010 http://php.net/manual/en/control-structures.foreach.php Link to comment https://forums.phpfreaks.com/topic/193047-foreach-loop/#findComment-1016705 Share on other sites More sharing options...
akshay Posted February 23, 2010 Author Share Posted February 23, 2010 Thanks a lot man! Link to comment https://forums.phpfreaks.com/topic/193047-foreach-loop/#findComment-1016805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.