Jump to content

Help Global Variable


bugzy

Recommended Posts

Ok i have this variable on my edit_information.php

 

$day = 12

 

on that edit_information.php I'm using a function that is located at function.php, now I want to use that $day variable on the function that I'm using..

 

I have tried this on edit_information.php .

 

global $get_day;

 

 

but it aint working...

 

 

Anyone?

 

Link to comment
Share on other sites

Post the code.

 

edit_information.php

 

 

require_once("../includes/functions.php");

$get_day = substr($get_birthdate,8,;
$get_month = substr($get_birthdate,5,2);
$get_year = substr($get_birthdate,0,4);

global $get_day;
global $get_month;
global $get_year;

 

 

I want to use that $get_day, $get_month and $get_year to one of the function in function.php

 

like this

 

function me_date_dropdown($year_limit = 0){

if($get_day == $day)
{
  //output something here
}


}

 

 

:shrug:

Link to comment
Share on other sites

The global keyword means nothing outside of a function.

 

It is used:

 

$a = 'foo';

function something() {
  global $a;
  echo $a;
}

something();

 

Having said that. Globals completely break the encapsulation that function provide. You should pass data to functions via there arguments.

Link to comment
Share on other sites

The global keyword means nothing outside of a function.

 

It is used:

 

$a = 'foo';

function something() {
  global $a;
  echo $a;
}

something();

 

Having said that. Globals completely break the encapsulation that function provide. You should pass data to functions via there arguments.

 

Now I get it! It's now working!

 

Thanks Thorpe!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.