Jump to content

[SOLVED] How to declare global variables?


kks_krishna

Recommended Posts

Let me put it clear.

For example I have two files : detail.php and common.php

 

Here detail.php is the file where we write the logic. Common.php is used for delaring all the common variables used across the files. take one scenario, i want to display 10 rows per page, so i will add one variable as rows_per_page = 10; in common.php. I want to use this varible in detail.php bcos it can be used in other files also. so did like this:

 

common.php

-----------

class{

  rows_per_page=10;

}

 

detail.php

---------

 

class Detail{

    function m(){

        // i want to use that variable here. how can i do that.

    }

 

 

Pleaes help me.

 

}

common.php

 

//Class not needed here...
/*
class{
   rows_per_page=10;
}
*/

//instead... and you can use '10' (single quoted) if you want it a string

define('_ROWS_PER_PAGE', 10);

 

detail.php

 

class Detail{
    function m(){
        echo "Rows Per Page = " . _ROWS_PER_PAGE;
    }


}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.