php - How do I use variables from outside in my function? -


i saw other user here asking , tried said in answer section, nothing had worked me.

i have variable:

$inputs = \request::all(); $domain = $inputs['domain']; 

now in $domain domain-name need.

this function:

function searchfor ($search) {     $path = '/var/www/laravel/logs/vhosts/';     $shell_exec = shell_exec("grep -c -i $search  $path" . $domain . ".log");     return $shell_exec; } 

this haven't worked cause of course php doesn't know $domain is.

now tried put global $domain; in function haven't worked either.

i tried this:

function anzahlsuche($search) use ($domain) { ... } 

but it's same, doesn't worked me.

does have idea can do?

i'm using laravel framework, maybe knows solution in laravel, normal php too, of course.

two options - pass variable parameter function or use global expression name variable within function. variable must available in scope function called.

 $inputs = \request::all();  $domain = $inputs['domain'];   function anzahlsuche($search,$domain)         {             $path = '/var/www/laravel/logs/vhosts/';             $shell_exec = shell_exec("grep -c -i $search  $path" . $domain . ".log");             return $shell_exec;         }   function anzahlsuche($search)         {             global $domain;             $path = '/var/www/laravel/logs/vhosts/';             $shell_exec = shell_exec("grep -c -i $search  $path" . $domain . ".log");             return $shell_exec;         } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -