php - Array isn't being seen by function.. storing in variable a no-no? -



php - Array isn't being seen by function.. storing in variable a no-no? -

i've googled around , didn't see answer. have array i'm storing in variable i'm trying pass function..

$myarr = 'array('item1', 'item2')'; require('script.php'); //where actual function makecode($myarr);

when utilize makecode(array('item1', 'item2')); works fine.. i've tried add together global $myarr makecode, didn't work either.

i'm thinking it's scope problem, maybe i'm misusing string. print_r($myarr) prints properly, isn't passing or something.

the function compares $myarr values , if matches what's in function's array, outputs right html, didn't list it. works, not variable.. thanks!

--makecode()-- function makecode($listarr){ /* global $myarr; //tried */ $output = ''; $items = array( 'item1' => "code item1", 'item2' => "code item2" ) /* $myarr = $listarr; //tried */ foreach ($listarr $val) { if(array_key_exists($val, $items)){ if(strlen($output)>0) $output .="|"; //add sytnax $output .="$items[$val]"; } } }

that's pretty much it.

$myarr = 'array('item1', 'item2')';

$myarr string here. i'm not sure that's meant. try:

$myarr = array('item1', 'item2');

if meant behave differently calling

makecode(array('item1', 'item2'));

because calling using actual array.

php variables scope

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -