Jump to content


quick php question


3 replies to this topic

#1 CoryMathews

    P2L Jedi

  • Members
  • PipPipPip
  • 554 posts
  • Gender:Male
  • Location:Texas

Posted 07 November 2007 - 06:15 PM

In some languages like python you can just say

for a in b
do something

with a being a primative and b being a list

can this be done in php or do i have to do it the c/java.. way with arrays and all that mess.

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 07 November 2007 - 06:17 PM

Yes there is, it's foreach:
http://php.net/manua...res.foreach.php

grtz

Bart

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 07 November 2007 - 07:02 PM

Note that as referenced in that manual, iterating through an object (such as a list) is not conveniently possible in php < 5.

foreach() only works on arrays with that exception (their while(list...each) method being the supperior method, but still not able to handle objects).

#4 CoryMathews

    P2L Jedi

  • Members
  • PipPipPip
  • 554 posts
  • Gender:Male
  • Location:Texas

Posted 08 November 2007 - 09:50 AM

well im not dealing with object just yet but imma give both the foreach a try see if it was what i was hoping for.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users