0

I am having troubles replacing a value in an array. I am showing that the status is changed to 'INACTIVE' but the change doesn't seem to reflect the array that I am trying to change. Any help would be appreciated. The variable is declared within the same page and I am unsure if there is an issue with scope, but I am fairly sure that isn't the case.

Here is what I have:

foreach ($ARG_WP_Payflow_Recurring_Billing_Profiles as $key => $value){
if($value['PROFILEID'] == $_POST['DeactivateProfile']){
    echo 'DING FRIES ARE DONE!<br>'.$value['STATUS'].' '.$value['PROFILEID'];
    $value['STATUS'] = "INACTIVE";
    echo '<br><br>'.$value['STATUS'];
    echo '<pre>';
    print_r ($ARG_WP_Payflow_Recurring_Billing_Profiles);
    echo '</pre>';
}

This is what I get as a result when passing 'RT0000000805'

DING FRIES ARE DONE!
ACTIVE RT0000000805

INACTIVE
Array
(
    [0] => Array
        (
            [FIRSTNAME] => John
            [LASTNAME] => Doe
            [ZIP] => 95101
            [ACCT] => 5100
            [EXPDATE] => 1215
            [STATUS] => ACTIVE
            [PROFILEID] => RT0000000805
        )

    [1] => Array
        (
            [FIRSTNAME] => John
            [LASTNAME] => Doe
            [ZIP] => 95101
            [ACCT] => 5100
            [EXPDATE] => 1215
            [STATUS] => ACTIVE
            [PROFILEID] => RT0000000806
        )

    [2] => Array
        (
            [FIRSTNAME] => John
            [LASTNAME] => Doe
            [ZIP] => 95101
            [ACCT] => 5100
            [EXPDATE] => 1215
            [STATUS] => ACTIVE
            [PROFILEID] => RT0000000807
        )

)
  • Am I correct in assuming you are looping through `$ARG_WP_Payflow_Recurring_Billing_Profiles` with a foreach and that is why you have a variable called `$value`? – RisingSun Aug 05 '15 at 00:13
  • 2
    ^^ If that is the case (you're inside a `foreach`, then you need to be iterating `$value` by reference for modifications to stick `foreach ($ARG_WP_Payflow_Recurring_Billing_Profiles as &$value)` (near the top of the foreach docs: http://php.net/manual/en/control-structures.foreach.php) – Michael Berkowski Aug 05 '15 at 00:16
  • It looks like, that you have an array inside another array. Try something like this: `$value[0]['STATUS'] = "INACTIVE";` Would help if we could see how your array is created. `$value` i mean. – Jo Smo Aug 05 '15 at 00:24
  • I did not notice that I didn't have the first loop. I think that you guys are right. I am looking into it now. The struggle I am/was having is that I need to change the 'STATUS' based on the 'PROFILEID' that is passed. I am attempting to update a WordPress database containing recurring billing profile IDs. This is my first stab at a plugin. – PayPal_MSI_Marshal Aug 05 '15 at 00:28
  • 2
    Okay yes, you need to either use the reference `&$value` per my earlier comment, or you can also modify it on the parent using `$key` inside the loop instead of the iterator `$value` as in `$ARG_WP_Payflow_Recurring_Billing_Profiles[$key]['STATUS'] = 'INACTIVE';` – Michael Berkowski Aug 05 '15 at 00:32
  • Closed it just before I hit send on my answer. : P – John Green Aug 05 '15 at 00:33
  • I had an answer too! Multidimensional arrays! – Parfait Aug 05 '15 at 00:33
  • I didn't know I needed an '&' added to the '$value'. Once I added the '&' the issue was resolved. Thank you so much for all of your help. – PayPal_MSI_Marshal Aug 05 '15 at 00:37

0 Answers0