0

I have to return some data by calling function, but global variable values we can't access inside function so I used global keyword,however after using global keyword it is making that variable empty,but I have to check condition by using that variable, so how to prevent variable values which is get replaced by global keyword,

    $url = $_SERVER['REQUEST_URI'];
    $url = explode('/', $url);
    $url = end(url);
    $param='some_value';

    active(); // call active unction

    function active() 
    {
        global $url, $param;
      // after using global keyword  $url,$param values replaced with empty by global keyword     
    }
Vimal
  • 1,140
  • 1
  • 12
  • 26
Anonymous
  • 1,074
  • 3
  • 13
  • 37

2 Answers2

0

try to use $GLOBALS['url'] ,$GLOBALS['param'], your function returning empty because $url and $param are not declared inside the function, initially $url and $param are not global variable

idirsun
  • 474
  • 6
  • 8
0
<?php

    $url = $_SERVER['REQUEST_URI'];
    $url = explode('/', $url);
    $url = end($url); // You miss `$` sign here.

    $param='some_value';

    active(); // call active unction

   function active() {
        global $url, $param;
        echo $url;
        echo $param;            
   }

?>
Amit Senjaliya
  • 2,867
  • 1
  • 10
  • 24