variable in function parameter

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default variable in function parameter

    Hello. Let's say I have something like this:

    function aa($test) {
    $a = 8;
    echo $test;
    }

    $a = 2;
    aa("a is ". ($a>5?"greater":"equal to or less"). " than 5".);


    I want this to output "a is greater than 5".. how can i modify the code so
    that the function parameter is evaluated inside the function?


    386-Dx Guest

  2. Similar Questions and Discussions

    1. variable in an object parameter?
      This may be a very simple post or may be something that shows my lack of understanding of html, but... I am trying to create an object that is a...
    2. session variable and URL parameter question
      Hello, if anyone could help us that would be fantastic: We have created a recordset that uses as a parameter a URL parameter ( URL.Course_ID)...
    3. Parameter Search Using Form Variable
      I have a connection to the SQL Server 2000 database and a data set made up a a collection of personnel records. I set up the data set with a...
    4. interpolating a variable with a request parameter
      Try with $q->param("qty$i"); thereis no variable interpolation in '' but when u use "" variable interpolation works. regards, KM...
    5. variable as a parameter
      <?php echo "<frame src=http://localhost/example.php?first=first name = top>"; echo "<frame src=http://localhost/test.php?first=first name =...
  3. #2

    Default Re: [PHP] variable in function parameter

    * Thus wrote 386-DX (murat@robcol.k12.tr):
    > Hello. Let's say I have something like this:
    >
    > function aa($test) {
    > $a = 8;
    > echo $test;
    > }
    >
    > $a = 2;
    > aa("a is ". ($a>5?"greater":"equal to or less"). " than 5".);
    [url]http://php.net/eval[/url]


    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  4. #3

    Default Re: [PHP] variable in function parameter

    > * Thus wrote 386-DX (murat@robcol.k12.tr):
    > > Hello. Let's say I have something like this:
    > >
    > > function aa($test) {
    > > $a = 8;
    > > echo $test;
    > > }
    > >
    > > $a = 2;
    > > aa("a is ". ($a>5?"greater":"equal to or less"). " than 5".);
    >
    > [url]http://php.net/eval[/url]
    No... you need to make $a global within the function for that change to
    affect $a outside the function

    function (...)
    {
    global $a;
    $a = 8;

    (can maybe do that in one operation, try it and see)

    ---John Holmes...

    Cpt John W. Holmes Guest

  5. #4

    Default Re: [PHP] variable in function parameter

    * Thus wrote CPT John W. Holmes (holmes072000@charter.net):
    > > * Thus wrote 386-DX (murat@robcol.k12.tr):
    > > > Hello. Let's say I have something like this:
    > > >
    > > > function aa($test) {
    > > > $a = 8;
    > > > echo $test;
    > > > }
    > > >
    > > > $a = 2;
    > > > aa("a is ". ($a>5?"greater":"equal to or less"). " than 5".);
    > >
    > > [url]http://php.net/eval[/url]
    >
    > No... you need to make $a global within the function for that change to
    > affect $a outside the function
    >
    > function (...)
    > {
    > global $a;
    > $a = 8;
    >
    > (can maybe do that in one operation, try it and see)
    A yes, I did forget to mention that but as per requested I was
    assuming they wanted the string test to be evalulated.

    <snip>
    I want this to output "a is greater than 5".. how can i modify the
    code so that the function parameter is evaluated inside the
    function?
    </snip>



    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  6. #5

    Default Re: [PHP] variable in function parameter

    Yes.

    I simplified the example for clearance but what I really want is to send a
    string as a parameter which includes variable names to be processed inside
    the function. eval() works fine, but I'm sure there was another way.


    "Curt Zirzow" <curt@zirzow.dyndns.org> wrote in message
    news:20030728145202.GP93863@bagend.shire...
    > * Thus wrote CPT John W. Holmes (holmes072000@charter.net):
    > > > * Thus wrote 386-DX (murat@robcol.k12.tr):
    > > > > Hello. Let's say I have something like this:
    > > > >
    > > > > function aa($test) {
    > > > > $a = 8;
    > > > > echo $test;
    > > > > }
    > > > >
    > > > > $a = 2;
    > > > > aa("a is ". ($a>5?"greater":"equal to or less"). " than 5".);
    > > >
    > > > [url]http://php.net/eval[/url]
    > >
    > > No... you need to make $a global within the function for that change to
    > > affect $a outside the function
    > >
    > > function (...)
    > > {
    > > global $a;
    > > $a = 8;
    > >
    > > (can maybe do that in one operation, try it and see)
    >
    > A yes, I did forget to mention that but as per requested I was
    > assuming they wanted the string test to be evalulated.
    >
    > <snip>
    > I want this to output "a is greater than 5".. how can i modify the
    > code so that the function parameter is evaluated inside the
    > function?
    > </snip>
    >
    >
    >
    > Curt
    > --
    > "I used to think I was indecisive, but now I'm not so sure."

    386-Dx Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139