Deux dollars sur une variable en PHP

Bonjour,
Dans certains codes PHP je trouve deux dollars au lieu d'une dans la variable.
Je voudrais donc savoir à quoi ça sert de mettre deux variables comme ceci en PHP
$$mavariable = get_posts($$mavariable);
if ($$mavariable == '') {
// etc ...
J'attends donc une explication
Merci

4 réponses

  1. Modérateur
    Cela sert à déréférencer une variable.
    exemple:
    johand@osiris:~/src/ccm/php$ cat deref.php  
    <?php 
    $xx= 3.1415905; 
    $yy= 2.7182818; 
    
    $myref="xx"; 
    printf("%f\n",$$myref); 
    $myref="yy"; 
    printf("%f\n",$$myref); 
    ?> 
    johand@osiris:~/src/ccm/php$ php deref.php  
    3.141590 
    2.718282


    Johan

    Gates gave ^H sold you the windows.
    GNU gave us the whole house.(Alexandrin)
    1. C est une variable dynamique
      <?php
      $variable = "president";
      $$variable = "Sarkozy";

      echo $president;
      //affichera Sarkozy
      ?>
      1. Plus clairement selon moi :
        $age = 18;
        $param = 'age';

        print( $age ); // Affiche 18
        print( $$param ); // Affiche 18