473,785 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to iterate throut an array?

Hello,
I have an array like this:

Array
(
[0] =Array
(
[1] =Array
(
[ID] =7A585DC0
[Co] =Array
(
[C] =nat
[b] =7A585DC0
)

[T] =Array
(
[1] =Array
(
[ID] =>7A585DC0

I want to delete some items from it. I think I have to do it recursively,
but PHP says:
"Fatal error: Only variables can be passed by reference in c:\www\p.php on
line 51"

The function looks like this:

function Del(&$tresc)
{
if (is_array($tres c['T'])) Del($tresc['T']);
else if (!$tresc['T'])
{
for ($x=0;$x<count( $tresc);$x++)
{
Del($tresc[$x]); //THIS IS LINE 51
}
}
else if (($tresc['Co']['C']=='hl') and
(!$tresc['Co']['n']))
array_splice($t resc,0,1);
}

How to iterate through all elements and delete some of them?

Regards,
Talthen
Aug 9 '06 #1
5 1706
talthen.z-serwera.o2 wrote:
How to iterate through all elements and delete some of them?
Take a look at

http://www.php.net/manual/en/control...es.foreach.php

You should be able to set up a function that iterates through the array and
does what you want.

HTH,
--
Benjamin D. Esham
bd*****@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
Go not to Usenet for counsel, for they will say both yes and no.
Aug 9 '06 #2
ta************* *****@nospam.pl wrote:
The function looks like this:

function Del(&$tresc)
{
if (is_array($tres c['T'])) Del($tresc['T']);
else if (!$tresc['T'])
{
for ($x=0;$x<count( $tresc);$x++)
{
Del($tresc[$x]); //THIS IS LINE 51
}
}
else if (($tresc['Co']['C']=='hl') and
(!$tresc['Co']['n']))
array_splice($t resc,0,1);
}

How to iterate through all elements and delete some of them?

Regards,
Talthen
Well, I'm not sure if it is causing the specific error you mentioned,
but one of your problems is the line:
for ($x=0;$x<count( $tresc);$x++)

In the array you gave as an example, you have some non-numeric key
values. Iterating a variable in order to do $tresc[$x] only works if
you have integer keys in order, such as
$tresc[0],$tresc[1],$tresc[2]...etc. For non-numeric keys, use the
foreach control structure.

Aug 9 '06 #3
Benjamin D. Esham wrote:
>You should be able to set up a function that iterates through the array and
does what you want.
mootmail-googlegroups[a_t]yahoo.com wrote:
In the array you gave as an example, you have some non-numeric key
values. Iterating a variable in order to do $tresc[$x] only works if
you have integer keys in order, such as
$tresc[0],$tresc[1],$tresc[2]...etc. For non-numeric keys, use the
foreach control structure.
Hm... thank you. I didn't know that. I thought it will enumerate all
possible keys. Will try with foreach.

Thank you both,
Talthen
Aug 9 '06 #4
Foreach is not a good solution in this task. I need to delete parent of
elements with specified value.
Let's say I have an array:
[0]-->[a]-->[A]
\-[b]
[1]-->[b]

Now I need to delete element [a] when its elements [A] and [b] have values
of, let's say, 1.
When I do foreach I cannot say what's the value of a parent or child of
current element.

Do you know how can I solve that?

Regards,
Talthen
Aug 10 '06 #5
Ok, array_walk works fine, but I cannot delet elements ;/

Regards,
Talthen
Aug 10 '06 #6

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

Similar topics

6
3957
by: ChronoFish | last post by:
Hi there, I want to iterate through an array starting at a known index. However the indexes are not linear. For example I have an array of events keyed by timestamp. $eventList = array (1064263264 => "event1", 10642635555 => "event2", 1064266666 => "event3", 1064267782 => "event4", 1064268812 => "event5"); I basically want to do a "for" or "foreach" but I don't necessarily want to start at key 1064263264 (event1).
2
2213
by: deko | last post by:
I have a file that contains the output of time(). A different time is on each line of the file, and each line represents a visit to the website. I want to calculate the total visits per day, month and year. So, I dump the file into an array, and then iterate through the array testing each element and incrementing a counter for each respective time period. But what is the best way to iterate through the array? The foreach($av) does...
1
6464
by: | last post by:
I'm going a little crazy trying to learn how to use arrays as properties in VBScript classes. Hopefully someone can help. First, I can't figure out whether it's possible to iterate through the members of an array that I have assigned to a propety. Second, I'm finding the question of "Property Let" versus "Property Set" to be very confusing. I have this code that utilizes a custom class I've defined, called clsGroup: myString =...
4
6303
by: nicolas | last post by:
Hello,everybody I get a problem: 1. Have an Int Array; 2. Run iterate over a range of Array once; 3. Get Minimum result and No.2 minimum result;
5
2700
by: Martin Pöpping | last post by:
Hello, I want to iterate the second dimension of a 2-dim-array. Let´s say I have an array: double myArray and a given index: int i. Assume my index is given in want to iterate my array with something like this:
7
7423
by: Jacob JKW | last post by:
I need to iterate over combinations of n array elements taken r at a time. Because the value of r may vary quite a bit between program invocations, I'd like to avoid simply hardcoding r loops. I assume the best way to do this would be either using closures or creating some sort of iterator class. Any guidance on how to get started? Thanks,
5
2483
by: Manish Tomar | last post by:
Hi, I know that using for in loop to iterate over array elements is a bad idea but I have a situation where it is tempting me to use it. I have a two dimensional sparse array say "arr" which will have length to be some 50 but will have some elements like arr, arr, arr at random locations. Each of these elements is again an array (since it is two dimensional) say arr, arr & so on for arr also. Currently I've coded it like this: for...
1
2548
by: nagarwal | last post by:
hi frnds, I am facing a prblm in displaying the contents of an ArrayList which contains 'String' Objects using logic:iterate tag.. example: in the Action : String s=null; String s1=null; s="hi";
25
25451
RMWChaos
by: RMWChaos | last post by:
Any JSON experts out there? I'd like to know if it is possible, and if so how, to iterate through a JSON property list so that each iteration selects the next value for each object. Here is an example list: function myFunction() { createDOM({ 'id' : , 'dom' : , 'parent' : "content", 'form' : ,
0
9645
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
10155
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
10095
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
9954
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
8979
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
6741
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.