Renameing variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boyd Pearson

    Renameing variables

    Below is a section of my code - i would like to be able to put the
    variable renaming bit in to a function so that i don't have to keep
    cutting and pasting it. the function would take (in this case) $sculp and
    $paint_draw as its arguments. I spent a very long day failing to get it
    to work -any help appreciated.



    PHP:
    -------------------------------------------------------------------------
    -------

    case artbycas:

    $table_name = array('artbycas _paint_draw', 'artbycas_sculp ');
    create_output($ table_name);

    randomize (1,2); //pick $numbers
    $z = 1;
    foreach ($numbers as $currNum){
    $paint_draw[$z++] = $output[$currNum]; //rename $output[foo]
    } //$paint_draw[1] , $paint_draw[2]

    randomize (3,4);
    $z = 1;
    foreach ($numbers as $currNum){
    $sculp[$z++] = $output[$currNum];
    }

    break;

    -------------------------------------------------------------------------
    -------


    --
    *************** *************** ********
    The Eldritch Dark:
    Dedicated to Clark Ashton Smith

  • Randell D.

    #2
    Re: Renameing variables


    "Boyd Pearson" <boyd@dont.spam .me> wrote in message
    news:MPG.19da21 e218c8a3f298968 7@news.slingsho t.co.nz...[color=blue]
    > Below is a section of my code - i would like to be able to put the
    > variable renaming bit in to a function so that i don't have to keep
    > cutting and pasting it. the function would take (in this case) $sculp and
    > $paint_draw as its arguments. I spent a very long day failing to get it
    > to work -any help appreciated.
    >
    >
    >
    > PHP:
    > -------------------------------------------------------------------------
    > -------
    >
    > case artbycas:
    >
    > $table_name = array('artbycas _paint_draw', 'artbycas_sculp ');
    > create_output($ table_name);
    >
    > randomize (1,2); //pick $numbers
    > $z = 1;
    > foreach ($numbers as $currNum){
    > $paint_draw[$z++] = $output[$currNum]; //rename $output[foo]
    > } //$paint_draw[1] , $paint_draw[2]
    >
    > randomize (3,4);
    > $z = 1;
    > foreach ($numbers as $currNum){
    > $sculp[$z++] = $output[$currNum];
    > }
    >
    > break;
    >[/color]

    I have some difficulty understanding exactly what you want to do - I believe
    you want $paint_draw to have a copy of $output, except that $paint_draw has
    its elements in random order (when compared to $output).

    True?

    If thats the case, why not try something like what I have below, instead of
    a foreach loop?

    <?
    srand((float) microtime() * 10000000);
    $paint_draw=shu ffle($output);
    ?>

    OR

    <?
    srand((float) microtime() * 10000000);
    $numberOfElemen ts=count($outpu t);
    $paint_draw=arr ay_rand($output , $numberOfElemen ts);
    ?>


    Comment

    • Boyd Pearson

      #3
      Re: Renameing variables

      In article <eQJbb.1018948$ 3C2.22684288@ne ws3.calgary.sha w.ca>,
      you.can.email.m e.at.randelld@y ahoo.com says...[color=blue]
      >
      > "Boyd Pearson" <boyd@dont.spam .me> wrote in message
      > news:MPG.19da21 e218c8a3f298968 7@news.slingsho t.co.nz...[color=green]
      > > Below is a section of my code - i would like to be able to put the
      > > variable renaming bit in to a function so that i don't have to keep
      > > cutting and pasting it. the function would take (in this case) $sculp and
      > > $paint_draw as its arguments. I spent a very long day failing to get it
      > > to work -any help appreciated.
      > >
      > >
      > >
      > > PHP:
      > > -------------------------------------------------------------------------
      > > -------
      > >
      > > case artbycas:
      > >
      > > $table_name = array('artbycas _paint_draw', 'artbycas_sculp ');
      > > create_output($ table_name);
      > >
      > > randomize (1,2); //pick $numbers
      > > $z = 1;
      > > foreach ($numbers as $currNum){
      > > $paint_draw[$z++] = $output[$currNum]; //rename $output[foo]
      > > } //$paint_draw[1] , $paint_draw[2]
      > >
      > > randomize (3,4);
      > > $z = 1;
      > > foreach ($numbers as $currNum){
      > > $sculp[$z++] = $output[$currNum];
      > > }
      > >
      > > break;
      > >[/color]
      >
      > I have some difficulty understanding exactly what you want to do - I believe
      > you want $paint_draw to have a copy of $output, except that $paint_draw has
      > its elements in random order (when compared to $output).
      >
      > True?[/color]

      Sort of $numbers will be two randomly generated numbers with in a
      predifined scope say 19 and 4 . so i want

      $paint_draw[1] = $output[19];
      $paint_draw[1] = $output[4];

      i have over a dozen sections (such as paint_draw and sculp) so i want to
      be able to pass $paint_draw or $sculp (as foo) or one of the other dozen,
      along with the two numbers in $numbers to create

      $foo[1] = $output[19];
      $foo[1] = $output[4];


      I imagine it would look something like

      randomize (3,4); //has created unique $numbers
      renameit($sculp ); //sends $sculp for the new variable name

      and then the function

      function renameit($var){
      $z = 1;
      foreach ($numbers as $currNum){
      $var[$z++] = $output[$currNum]; //creates $sculp[1 and 2]
      }
      }



      --
      *************** *************** ********
      The Eldritch Dark:
      Dedicated to Clark Ashton Smith

      Comment

      Working...