9, January 2009

Array prob - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Array prob
« previous next »
Pages: [1] Print

Author Topic: Array prob  (Read 850 times)
Raped By Google
*
Gender: Female
Posts: 27
240 credits
Members referred : 0



« on: Sep 10, 2005, 05:59:42 PM »

I have an array of this form :

Code:
<?php
$ar 
= array(
"a" => "value1",
"b" => "value2",
...............
..........
............
);
?>


and I want to create a loop in which I will have to use the key and the value.

How can I do this?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8357
43129 credits
Members referred : 3



« Reply #1 on: Sep 10, 2005, 06:03:50 PM »

There are two ways to do this (actually there is a third using the array_keys function but not too fast):

Solution 1 :

Code:
<?php
foreach($ar as $key => $value)
{
     
//Your code here
}
?>


Solution 2 :

Code:
<?php
while ($value current($ar) ) {
  
$key =  key($ar);
  
//Your code here 
  
next($ar);
}
?>


Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #2 on: Sep 12, 2005, 09:38:06 PM »

Hey Nikolas, how long have you been coding in PHP? You seem to know a lot.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8357
43129 credits
Members referred : 3



« Reply #3 on: Sep 12, 2005, 09:53:22 PM »

Hey Nikolas, how long have you been coding in PHP? You seem to know a lot.

Thanks for your good words man.

I am coding with php for about 3-4 years

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #4 on: Sep 13, 2005, 03:12:53 AM »

Ah nice, I have been doing PHP for about 1 year maybe? I know the basics to make PHP Scripts but theres still a lot to learn.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=121
Tags : php Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Array prob
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jan 09, 2009, 08:52:27 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 38.657
Total Topics: 7.772
Total Members: 4.660
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: mahendra

27 Guests, 4 Users online :

15 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2009 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.