Connecting Tech Pros Worldwide Forums | Help | Site Map

help with unset

Iain Adams
Guest
 
Posts: n/a
#1: Aug 10 '06
Hey i have a loop like so,


foreach($users as $user)
{
foreach($syncWebUsers as $sync)
{
//user already synched
if($sync['crmid'] == $user[$crmid])
{
echo "User Already
Synched".$user[$crmid];
unset($user);
}
}
}

Now I wanted this to completely remove the sub array $user from $users
but when $users remains unchanged when I print_r it. I guess this is to
do with referencing things. Does anyone know how to combat this problem.


Chung Leong
Guest
 
Posts: n/a
#2: Aug 10 '06

re: help with unset


Iain Adams wrote:
Quote:
Hey i have a loop like so,
>
>
foreach($users as $user)
{
foreach($syncWebUsers as $sync)
{
//user already synched
if($sync['crmid'] == $user[$crmid])
{
echo "User Already
Synched".$user[$crmid];
unset($user);
}
}
}
>
Now I wanted this to completely remove the sub array $user from $users
but when $users remains unchanged when I print_r it. I guess this is to
do with referencing things. Does anyone know how to combat this problem.
No, not really. Unsetting $user will unset $user, not something in in
$users. To unset the element in $users, you have to specify it. Hence:

foreach($users as $user_index =$user) {
...
unset($users[$user_index]);
...
}

Iain Adams
Guest
 
Posts: n/a
#3: Aug 11 '06

re: help with unset


Cheers Chung, that worked!!!!

Chung Leong wrote:
Quote:
Iain Adams wrote:
Quote:
Hey i have a loop like so,


foreach($users as $user)
{
foreach($syncWebUsers as $sync)
{
//user already synched
if($sync['crmid'] == $user[$crmid])
{
echo "User Already
Synched".$user[$crmid];
unset($user);
}
}
}

Now I wanted this to completely remove the sub array $user from $users
but when $users remains unchanged when I print_r it. I guess this is to
do with referencing things. Does anyone know how to combat this problem.
>
No, not really. Unsetting $user will unset $user, not something in in
$users. To unset the element in $users, you have to specify it. Hence:
>
foreach($users as $user_index =$user) {
...
unset($users[$user_index]);
...
}
Closed Thread