Jump to content

Unset Child Won't Remove From Parent


unemployment

Recommended Posts

My guess would be that the condition is never true. Without examining the data there's no way to be sure. But, you can add some debugging code to check for yourself

foreach ($data[0] as $k => $r)
{
    //Debugging code:
    echo ($r['feedid'] !== $user_info['uid']) ? "'{$r['feedid']}' !== '{$user_info['uid']}'" : "'{$r['feedid']}' === '{$user_info['uid']}'";
    echo " : ";
    echo ($r['action_id'] == 'newuser') ? "'{$r['action_id']}' == 'newuser'" : "'{$r['action_id']}' != 'newuser'";
    echo (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser')) ? "TRUE" : "FALSE";
    echo "<br>\n";

    if (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser'))
    {
        unset($data[0][$k]);
    }
}

 

If the results still don't look right try using var_dump() on the first two values since they must be the same value AND the same type.

Link to comment
Share on other sites

My guess would be that the condition is never true. Without examining the data there's no way to be sure. But, you can add some debugging code to check for yourself

foreach ($data[0] as $k => $r)
{
    //Debugging code:
    echo ($r['feedid'] !== $user_info['uid']) ? "'{$r['feedid']}' !== '{$user_info['uid']}'" : "'{$r['feedid']}' === '{$user_info['uid']}'";
    echo " : ";
    echo ($r['action_id'] == 'newuser') ? "'{$r['action_id']}' == 'newuser'" : "'{$r['action_id']}' != 'newuser'";
    echo (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser')) ? "TRUE" : "FALSE";
    echo "<br>\n";

    if (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser'))
    {
        unset($data[0][$k]);
    }
}

 

If the results still don't look right try using var_dump() on the first two values since they must be the same value AND the same type.

 

*rubs eyes*

 

Yup, time for bed.

Link to comment
Share on other sites

My guess would be that the condition is never true. Without examining the data there's no way to be sure. But, you can add some debugging code to check for yourself

foreach ($data[0] as $k => $r)
{
    //Debugging code:
    echo ($r['feedid'] !== $user_info['uid']) ? "'{$r['feedid']}' !== '{$user_info['uid']}'" : "'{$r['feedid']}' === '{$user_info['uid']}'";
    echo " : ";
    echo ($r['action_id'] == 'newuser') ? "'{$r['action_id']}' == 'newuser'" : "'{$r['action_id']}' != 'newuser'";
    echo (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser')) ? "TRUE" : "FALSE";
    echo "<br>\n";

    if (($r['feedid'] !== $user_info['uid']) && ($r['action_id'] == 'newuser'))
    {
        unset($data[0][$k]);
    }
}

 

If the results still don't look right try using var_dump() on the first two values since they must be the same value AND the same type.

 

Thanks for the code. The condition is being met.  I think the problem is just that the loop continues to run through all the variables even after the array is unset and still adds in content.  Is there anyway to tell the foreach to go to the next $k value after I unset the array? 

Link to comment
Share on other sites

Thanks for the code. The condition is being met.  I think the problem is just that the loop continues to run through all the variables even after the array is unset and still adds in content.  Is there anyway to tell the foreach to go to the next $k value after I unset the array? 

 

Not sure what you mean. The loop WILL continue to the next value on each iteration. Based upon the code you posted (assuming sequential, numerically based indexes) if the values for key ($K) 3 meet the criteria, $data[0][3] will be unset and the loop will start over with $k being equal to 4.

 

I think you are leaving out some pertinent information. however, I will add that I think you might want to look into using array_filter() with a custom function.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.