redarrow Posted March 24, 2006 Share Posted March 24, 2006 What is the main array i need to know best thank you.The arrays i am learning and lernt[code]example 1<?$lucky=array("food","dog","home","foot","pool","leg","body","head","teth","ear"); for($i=0; $i<count($lucky); $i++){echo "<br>$lucky[$i]<br>normal array";}?><?example 2$lucky=array("food"=>"dog","home"=>"foot","pool"=>"leg","body"=>"head","teth"=>"ear"); while(list($i, $j,)=each($lucky)){echo "<br>".$i."<br>".$j."<br>assotate array";}?><?example 3$lucky=array("dog","home","foot","pool","leg","body","head","teth","ear"); foreach( $lucky as $i => $j){echo "<br>".$i."<br>".$j."<br>forech array";}?><?example 4$lucky=array(array("food","dog","home","foot","pool","leg","body","head","teth","ear"), array("food","dog","home","foot","pool","leg","body","head","teth","ear")); echo"<br><br> ".$lucky[1][0]."<br>double array";?><?example 5$lucky=array("myarray1"=>array("food","dog","home","foot","pool","leg","body","head","teth","ear"),"myarray2"=>array("food"=>"a","home"=>"b","pool"=>"c","leg"=>"d","teth"=>"e")); echo"<br><br>".$lucky[myarray1][1]."<br>double array named";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5717-popular-array/ Share on other sites More sharing options...
SiC_Goat Posted March 25, 2006 Share Posted March 25, 2006 If the array will have string indexes this is pretty common$array = array("index1" => 1,"index2" => new Object(),"index3" => "string");If the array will use integer indexes and they are asigned at once$array = array("field1", "field2", "field3");If the array is added to via iterationfor($i=0;$i<$value;$i++){$array[$i] = $someSource;} Quote Link to comment https://forums.phpfreaks.com/topic/5717-popular-array/#findComment-20485 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.