Net123 Posted January 10, 2011 Share Posted January 10, 2011 i know this script is used for dispaly all values in an array i need all details about this code please teach me ..... for ( $i = 0; $i <= 4; $i ) { echo $myarray [ $i ]; } Link to comment Share on other sites More sharing options...
justsomeguy Posted January 10, 2011 Share Posted January 10, 2011 Go over the relevant tutorials and ask specific questions if you have them:http://www.w3schools.com/php/php_arrays.asphttp://www.w3schools.com/php/php_looping_for.asp Link to comment Share on other sites More sharing options...
birbal Posted January 10, 2011 Share Posted January 10, 2011 for ( $i = 0; $i <= 4; $i++) { echo $myarray [ $i ];} you need to use increment oprators eg. i++ in for loopit will initiate i=0 then will check condition if i lessthan equal to 4 it will enter itafter each rotation it will increase by 1and in the for loop echo will show up the value of particular index of myarraybut it only work with index array not with associative array. Link to comment Share on other sites More sharing options...
Net123 Posted January 10, 2011 Author Share Posted January 10, 2011 If the "$i" variable is just used for name or this is a important function ...Why we use the "for" ?and what is the meaning of "foreach" ?What is the difference beween for and foreach ?I can't find the mean in w3schools php tutorial thanks in advance for you ... Link to comment Share on other sites More sharing options...
iwato Posted January 10, 2011 Share Posted January 10, 2011 i know this script is used for dispaly all values in an arrayThe way it is written it will probably only display the array's first element. If it were to display more, it would only display the first five elements.If you wish to employ a for-statement to display all the elements of any array, you must first know how many elements the array contains. Then, you need to increment the iterative variable $i in such a way that it increases by one with each new iterative attempt. Roddy Link to comment Share on other sites More sharing options...
Net123 Posted January 10, 2011 Author Share Posted January 10, 2011 Wow W3schools is a first class website "forum" is really very excellent i get the answer within 2 minutes when i makes a new topic in this site ....this site was really very helpfull for newbie's like me anyway i need to say very thank's to this site and the forum moderator's and member's and everyone..... Link to comment Share on other sites More sharing options...
thescientist Posted January 10, 2011 Share Posted January 10, 2011 If the "$i" variable is just used for name or this is a important function ...Why we use the "for" ?and what is the meaning of "foreach" ?What is the difference beween for and foreach ?I can't find the mean in w3schools php tutorial thanks in advance for you ...did you read the links justsomeguy posted? Link to comment Share on other sites More sharing options...
boen_robot Posted January 10, 2011 Share Posted January 10, 2011 If the "$i" variable is just used for name or this is a important function ...A "$" followed by something defines a variable with a certain name. YOU choose the name. Always. Whatever name you choose, whenever you want to use the variable, you need to use that name.Why we use the "for" ?For convinience (excuse the pun). The same thing can be achieved by any other kind of a loop, but will be less convinient.what is the meaning of "foreach" ?Foreach takes an array, and loops over all of its elements. On every iteration, you have access to the current member via a variable name you choose yourself when you start the loop. For example (again: an example; all variables names can be anything you want):foreach($array as $key => $value) { will loop over the array in the $array variable, and at each iteration, you'll have access to the current array value in the $value variable, and the current array key in $key. What is the difference beween for and foreach ?"foreach" can only loop over arrays and certain special objects (long story...), whereas "for", "while" and "do...while" loop over until a certain condition is false. They don't care what you're looping over (if anything) - they only care if the condition that you've defined at the start is now false.I can't find the mean in w3schools php tutorial thanks in advance for you ...Have you tried here and here? Link to comment Share on other sites More sharing options...
Net123 Posted January 10, 2011 Author Share Posted January 10, 2011 Yeah i also readed what's important in that ? Link to comment Share on other sites More sharing options...
boen_robot Posted January 10, 2011 Share Posted January 10, 2011 Yeah i also readed what's important in that ?Like, "everything"? Especially at the "For loops" page, which contains information about foreach too. It basically says the same thing we just said. Link to comment Share on other sites More sharing options...
Net123 Posted January 10, 2011 Author Share Posted January 10, 2011 oh i am sorry now i know that from this forum and i finded that at w3schools php loop tutorial page really very thanks friends Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.