I've googled around and didn't see the answer. I have an array I'm storing in a variable that I'm trying to pass to a function..
$myArr = 'array('item1', 'item2')';
require('script.php'); //where actual function is
makeCode($myArr);
When I use makeCode(array('item1', 'item2')); it works fine.. I've even tried to add global $myArr to makeCode, but that didn't work either.
I'm thinking it's a scope problem, but maybe I'm misusing the string. print_r($myArr) prints properly, it just isn't passing or something.
The function basically just compares $myArr values and if it matches what's in the function's array, it outputs the correct HTML, so I didn't list it. It works, just not the variable.. Thanks!
--makeCode()--
function makeCode($listArr){
/* global $myArr; //Tried this */
$output = '';
$items = array(
'item1' => "Code for item1",
'item2' => "Code for item2"
)
/* $myArr = $listArr; //tried this too */
foreach ($listArr as $val) {
if(array_key_exists($val, $items)){
if(strlen($output)>0) $output .="|"; //Add Sytnax
$output .="$items[$val]";
}
}
}
That's pretty much it.