I agree that it's a matter of opinion. But I've gotta say that I *LOVE*
being able to treat *any* arbitrary string of text as a list (read:
array). Let me give you an example:

<cfset TheList = ListRest(CGI.HTTP_REFERRER,"?")>
<cfloop index="i" from="1" to="#ListLen(TheList,"&")#">
     <cfset ThisItem = ListGetAt(TheList,i,"&")>
     <cfif ListFirst(ThisItem,"=") EQ "numPageID">
        <cfset MyNumPageID = ListLast(ThisItem,"=")>
     </cfif>
 </cfloop>

This code allows me to treat one string of characters (the http_referrer
in this case) as three different arrays. I didn't have to create an
array out of any of it. The very powerful "List" functions allow me to
accomplish this, and CF handles the conversion to arrays eternally. This
is *not* to say that I can't create and manipulate arrays directly, and
that I *have to* use lists instead of arrays, that's just not true. I
can use the ArrayNew() or StructNew() functions to create arrays and
structures that I can easily reference and manipulate.

Er, you are aware that you can reference strings as arrays in PHP, or if needed convert a string to a real array in one line, right?

for ($i=0; $i < strlen($string); ++$i) {
 print $string[$i] . "\n";
}
foreach (explode($string) as $char) {
 print $char . "\n";
}

How do you tell PHP what the list delimiter is? In ColdFusion I can take a list like this:

<cfset str = "a,b,c,d|d,e,f,g*h,i,j,k|l,m,n,o">

I can then turn around and get the first element based on the asterisk being the delimiter and then treat the result (a,b,c,d|d,e,f,g) as a new list who's delimiter is the pipe and then end up with last list whose delimiter is the comma.

<cfloop index="i" from ="1" to="#ListLen(str, '*')#">
   <cfset str2 = ListGetAt(str, i, "*")>
   <cfloop index="n" from="1" to="#ListLen(str2, '|')#">
         <cfset str3 = ListGetAt(str2, n, "*")>
         <cfloop index="j" from="1" to="#ListLen(str3)#">
<!--- do some stuff with the innermost elements of the list --->
         </cfloop>
   </cfloop>
</cfloop>

Can you do that in php?

Cheers,
Chris
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to