Page 1 of 1

Referencing an array?

Posted: Wed Nov 26, 2003 5:21 pm
by webcan
Hi there ...

I'm wondering how I can do this in PHP...

If I create an array such as this:

$dow[1] = "Monday";
$dow[2] = "Tuesday";
...

And I have a SQL database which contains the number 1 in another array, $row["id"], how can I get it to reference Monday?

I tried $dow[$row["name"]] but that doesn't work.

Thanks,
Peter.

Posted: Wed Nov 26, 2003 5:35 pm
by infolock
$dow[1] = "Monday";
$dow[2] = "Tuesday";

And I have a SQL database which contains the number 1 in another array, $row["id"], how can I get it to reference Monday?
sorry, didn't quite follow what you are asking, but is this what you are trying to do ?

Code: Select all

<?php

if ($row["id"] = 1)
{
   echo $dow[1];
}

?>

Posted: Wed Nov 26, 2003 5:38 pm
by webcan
No... it's more like:

Variables:

$dow[1] = "Monday";
$row["id"] = 1;

Long way:

$temp = $row["id"];
$this = $dow[$temp];

What's the short way? :)

Posted: Wed Nov 26, 2003 6:40 pm
by mchaggis
simply:

Code: Select all

$this = $dow&#1111;$row&#1111;"id"]];

Posted: Wed Nov 26, 2003 6:45 pm
by webcan
Well aren't I clever.

You were right... that is correct, and it's what I initially thought (first email), it was coming up blank because I forgot to declare $dow globally.

:-X

THANKS!