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,121
  • 11
  • 23
Anonymous
  • 886
  • 1
  • 12
  • 23

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
  • 238
  • 2
  • 4
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,307
  • 1
  • 7
  • 20