473,666 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with unset

Hey i have a loop like so,
foreach($users as $user)
{
foreach($syncWe bUsers 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.

Aug 10 '06 #1
2 1567
Iain Adams wrote:
Hey i have a loop like so,
foreach($users as $user)
{
foreach($syncWe bUsers 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]);
...
}

Aug 10 '06 #2
Cheers Chung, that worked!!!!

Chung Leong wrote:
Iain Adams wrote:
Hey i have a loop like so,
foreach($users as $user)
{
foreach($syncWe bUsers 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]);
...
}
Aug 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2126
by: lawrence | last post by:
Given a bunch of mixes variables, I'm in a situation where I can't know what type they are. Can I use unset to kill an object? unset($object); Can I use unset to kill a pointer to an open file? unset($fp); Can I use unset to kill a pointer to a database return? unset($mySqlResult);
21
3381
by: steve | last post by:
Dont’ make my mistake. It is costly. Say you have defined a variable $var in your main script. Now in a function you access it using: global $var; But you want to set it to null inside the function. DO: $var = null; DONT DO: unset($var);
2
1214
by: Yannick Benoit | last post by:
Hi! I use this to find all links in a page : *(href)*=*(+) but recently i found out that it only works if links are setup this way: <a href = "... I would like to know if someone can help me find the proper expression which would work with <a href = "... <a href= "... <a href="... and <a href ="...
1
1884
by: frizzle | last post by:
Hi group, Why won't $new_var be unset in the following function? Am i missing out something? Greetings Frizzle. *************************************
3
2628
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm running into some PHP behavior that I do not understand in PHP 5.1.2. I need to parse the HTML from the following carefully constructed URI:
25
3315
by: crescent_au | last post by:
Hi all, I've written a login/logout code. It does what it's supposed to do but the problem is when I logout and press browser's back button (in Firefox), I get to the last login page. In IE, when I press back button, I get to the page that says "Page has Expired" but Firefox does not do this. I think it's something to do with sessions not properly unset or something like that but I haven't been able to figure it out. I am
5
2292
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray) || @sizeof($leaseObj->errorArray) == 0)) { print_r(array_keys($_POST)); @reset($_POST); $tempPost = $_POST; foreach ($_POST as $key =$val) if (strpos($key, 'new_') === 0) array_remove($tempPost, $tempPost);
9
6273
nine72
by: nine72 | last post by:
Ok, so I have figured out how to parse an custom returned XML doc (actually a string that I made into a doc for testing). At this point I am attempting to integrate my parse routine into my main code and I am having an issue getting it to mesh, and am looking for a little help in how to 1) combine the two and 2) how to catch the incoming xml string. FYI the string is sent to me as a return message to an xml message that I send first....
0
1413
Airslash
by: Airslash | last post by:
Hello, I've written a small function to delete a variable from a class' internal array. The variables on their own are custom class objects, and I'm a bit confused about the whole pass by reference thing. First I'll show you the code: # removes a parameter from the array. # variables are passed as reference to prevent overhead.
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.