Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: split string and loop through it
03-11-2007, 01:14 PM #1
- Join Date
- May 2004
- Thanked 0 Times in 0 Posts
split string and loop through it
I have the following code in asp that i'm trying to duplicate in php
what is does is split a string my commas and tehn i want to loop through it.
for i= lbound(arradminproductfieldnames) to ubound(arradminproductfieldnames)
' do sutff with the element of array
03-11-2007, 08:21 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,648 Times in 2,617 Posts
PHP and ASP are similar in how they look and feel, especially with the new object model. The solution you are looking for is like so:
$arradminproductfieldnames = explode(", ", adminproductfieldnames)
for ($i = 0; $i < count($arradminproductfieldnames); $i++)
// iterate using $arradminproductfieldnames[$i]
foreach ($arradminproductfieldnames AS $arradminItem
// Use $arradminItem as iterated value
Hope that helps you!
Oh, drop a quick message here as well.
Php also has a split() function, and will do the same as you are looking for. However, split in php is used in conjunction with regular expressions, and searches for a pattern. This technically makes it slower than an explode for simplistic search techniques.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');