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.

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.

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? 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.