Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts

    This may seem dense, but...

    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?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Are you talking about the variables in the {} brackets?
    It can be used like this:
    PHP Code:
    $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.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    <?
    $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.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Thanx!
    What I needed was an example which actually had what I was looking for, as opposed to the first. That answers my question!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •