It is currently Wed Feb 08, 2012 5:27 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Arrays in PHP
PostPosted: Fri Jul 30, 2010 5:00 pm 
Offline

Joined: Wed Jul 28, 2010 2:10 pm
Posts: 8
Hi! :)
In PHP, there are two types of arrays i.e. Indexed and Associative.
Indexed can be accessed, using for loop . Associative array can be accessed using foreach loop. Can Indexed array be accessed using foreach and Associative array using for loop?
I'm not able to implement that for single as well as multi-dimensional array. :?:
Can someone help me please :!:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2010 2:27 pm 
Offline

Joined: Wed Jul 28, 2010 2:10 pm
Posts: 8
Hi! :D
I tried alot, the only thing, that i got was we can access indexed array using foreach loop but we cannot access associative array using for-loop.
If, in case your using associative multi-dimensional array, then you hav to use for-loop, till to u reach actual associative array and then again use for-each loop. E.g:

$var1=array(array("MH"=>"Maharashtra", "KA"=>"Karnataka"),array("AM"=>"America", "AU"=>"Australia"));

echo "<h4> Using For-Each Loop:</h4>";
for($i=0;$i<count($var1);$i++)
{
foreach($var1[$i] as $key=>$value)
{
echo " ", $value;
}
}

Thanks and regards.
Shital. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to: