hello i have a php file named index.php.

within that file two php scripts are there ...

they have to share four $variables values with each other...how coud i do this??

global,superglobal or static???
`

If everything is contained within the same file, a static should be able to handle it. Without seeing your code it's difficult to tell. Just use some basic markup like:

class globals 
{
    static $var = "Hello world.";
}

echo globals::$var;

There's no reason why a global shouldn't, because if you're using classes you can call it in, and if you're not, a standard variable will be kept in memory throughout your script. Personally I find this a rather unorganised way to sort out your code though.

Finally, a superglobal is possilbe using the $GLOBALS variable to retrieve values. Again, it works but it's not very tidy.

So you're probably best in most cases to use a static, but thats only a generalised thing and in some cases I imagine one of the others might be better.

commented: agreed with this +0

post some come please

when you say to scripts, do you mean 2 sections like <?php ?>
are you talking about sharing variables between functions

i have defined them in a php file and just using them in another php file after including that defining php file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.