[thelist] 404 hack: thanks for a great idea! (php tip)

Eduardo Dominguez lalo_dominguez at yahoo.com
Tue Mar 13 10:56:08 CST 2001


You can have associative arrays in php.

> This_Array[3] = "whatever";
> document.images["Nav3"] = "whatever.gif";

That could be written as (putting aside the DOM stuff)

   $this_array[3] = 'whatever';
   $document_images['nav3'] = 'whatever.gif';

Also, you can use foreach() instead of the while loop you mentioned:

    foreach( $my_array as $key => $value )

for associative arrays, or

   foreach( $my_array as $value ) 

in case you dont have an associative array..


----- Original Message ----- 
From: "Ben Henick" <persist1 at io.com>
To: <thelist at lists.evolt.org>
Sent: Monday, March 12, 2001 7:50 PM
Subject: [thelist] 404 hack: thanks for a great idea!


The past week, I've been building a Weblog:

http://www.io.com/persist1/log.php

I struggled over how to give each entry its own URL until this morning,
when the content-negotiation method used on evolt.org came to mind.

Putting the functionality together was a snap - or at least as much a snap
as it could be, given that until a week ago I'd done as little of my own
PHP as I thought I could get away with at the time.

So, to Dan and anyone else who feels they deserve the credit:  thanks.

<tip type="PHP arrays vs. JavaScript arrays" author="Ben Henick">

While in JavaScript arrays can often be accessed by index:

This_Array[3] = "whatever";

or by key (especially in the DOM tree):

document.images["Nav3"] = "whatever.gif";

in PHP, many of the arrays you'll find yourself working with are not
nearly so versatile.

It's still easy in PHP to retrieve the length of an array, regardless of
its type:

i < count($this_array);

...but you'll find yourself working with while loops far more frequently
because many defined functions return arrays by key and not by index:

while(list($current_key,$current_entry) = each($this_array))
{ ... }

</tip>

...for what it's worth.  YMMV...


-- 
Ben Henick
Web Author At-Large
http://www.io.com/persist1/
persist1 at io.com

"Are you pondering what I'm pondering, Pinky?"
"I think so, Brain, but... (snort) no, no, it's too stupid."
"We will disguise ourselves as a cow."
"Oh!" (giggles) "That was it exactly!"



---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the thelist mailing list