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
https://forums.phpfreaks.com/topic/268394-help-global-variable/
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:

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.

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!

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.