View Full Version : This may seem dense, but...

10-01-2004, 08:42 PM
This is the first I've seen code structured this way. I just want to know if anyone knows how it works, and if its a standard php property of some sorts.

Anyway, its in the vB 3.x, I've noticed every once and awhile when the functions return a cache, its structured like so:
$whatevercache["{$variable1}-{$variable2}"] = $whateveritis.

Anybody know exactly what this does, or is it something simple like adding {prefix} in front of table queries? What I mean, is this something that jelsoft is using with customized functions, or is this something that php does predefined? If the latter, how does it work, and what is its benefits?

10-01-2004, 09:21 PM
Are you talking about the variables in the {} brackets?
It can be used like this:

$test = array('my_key' => 'User');
print "Hello {$test["my_key"]}!";

It makes it easy to use arrays with keys. Generaly not used. It can do some other things but all of them (almost) can be don in other ways.

10-01-2004, 10:09 PM
I'm more confused as to how it works, with the two variables within the brackets. Does that have any effect to how the array would come out, as opposed to running the same query with the cache as $whatevercache = $whateveritis?

10-02-2004, 09:09 AM
$cache = array('5-3' => 'It is 5-3', '2' => 'It returns 2');
$variable1 = 5;
$variable2 = 3;
print $cache["{$variable1}-{$variable2}"]; // Evaluates to '5-3' and returns 'It is 5-3'.
print $cache["$variable1-$variable2"]; // Evaluates to '5-3' and returns 'It is 5-3'.
print $cache[$variable1-$variable2]; // Evaluates to '2' and returns 'It returns 2'.
// print $cache[{$variable1}-{$variable2}]; // Syntax Error.

As I told you before it is only another way of doing it.

10-07-2004, 12:28 AM
What I needed was an example which actually had what I was looking for, as opposed to the first. That answers my question!