I am trying to simplify adding stuff to some arrays with a custom function in PHP.
$campaignLimits = array();
$couponLimits = array();
$subscriptions = array();
The function looks like this:
function DefineSubscription($itemname,$subscription,$campaignlimit,$couponlimit)
{
// Make em global
global $campaignLimits, $couponLimits, $subscriptions;
// Add stuff to the arrays
$campaignLimits[$itemname] = $campaignlimit;
$couponLimits[$itemname] = $couponlimit;
$subscriptions[$itemname] = $subscription;
return;
}
I am calling that function, like this:
DefineSubscription(
"1", // Item Name/Number
1, // Subscription ID
1, // Campaign Limit
30 // Coupon Limit
);
However, when I print_r($couponLimits);, I get Array.
The function and the Arrays are declared in a require_once‘d file.
I am obviously doing something wrong.. But what? 🙂
EDIT: By doing the print_r in the DefineSubscription function itself, I got the correct output. It appears my arrays are not global when I am including it? Isn’t it supposed to be?
if your using global vars you should adresse them with $GLOBALS to make sure your in the right context
Regards Thomas