473,503 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sing two arrays in a 'for each ..." statement

I was thinking along these lines initially but didnt know much about arrays.
So thought the easiest way was to use two separate fields. However the two
fields match, in that the commar separated numbers in one field match the
commar separated numbers in the other.
Ive used
$percentarray = explode(",", $brpercentgroup);
to create two separate keyed arrays for each field.

If I combined the fields (easy at this stage as the table has only recently
been created) how would I extract the field contents into an associative
array, as I presume that is what will be needed.
How would I modify it to create an associative array?
would it involve using the '=>' in the glue parameter somehow?

ie field contains 0,100,3,90,4,80,5,85,9,70
into an associative 0=>100,3=>90,4=>80,5=>85,9=>70
If the array was called $percentarray, I presume I would then use;

foreach ($percentarray as $yearvalue=>$percentvalue) {

to extract the two values to use in the function below?
*************
Function taper_rel($aim,
$yearsheld,$byrsheldgroup,$bpercentgroup,$nbyrshel dgroup,$nbpercentgroup){
if($aim = 1){
$yearsarray = explode(",", $byrsheldgroup);
$percentarray = explode(",", $brpercentgroup);
}elseif($aim = 0){
$yearsarray = explode(",", $nbyrsheldgroup);
$percentarray = explode(",", $nbrpercentgroup);
}
foreach ($yearsarray as &$yearvalue, $percentarray as &$percentvalue) {
if ($yearsheld==$yearvalue){
return $percentvalue;
}
}

unset($yearvalue);
unset($percentvalue);
}
***********************
Ian
"C." <co************@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
On 3 Nov, 15:15, "mantrid" <ian.dan...@virgin.netwrote:
Hello
I wish to extract two arrays and use them simultaneously in a for each
statement
Ive tried
'foreach ($yearsarray as &$yearvalue, $percentarray as &$percentvalue)
{'
and also
'foreach ($yearsarray as &$yearvalue AND $percentarray as
&$percentvalue) {'

If each entry in one array matches one in the other then:

foreach ($yeararray as $index=>$year) {
print $year, $percentarray[$index];
}

Even if these were not compound data structures (as indicated in the
remainder of your code) your data design is a mess; both values
should be held in the same record in the same array.

C.

Nov 5 '07 #1
0 1316

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

Similar topics

53
3609
by: Oliver Fromme | last post by:
Hi, I'm trying to write a Python function that parses an expression and builds a function tree from it (recursively). During parsing, lambda functions for the the terms and sub-expressions...
4
1787
by: dmiller23462 | last post by:
Somebody take a look and give me any suggestions? My brain is nuked... Here's my deal....I have online submission forms on my intranet at work here....I am appending to an Access DB with the...
27
11120
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
20
4652
by: Pavel Stehule | last post by:
Hello, Is possible merge two arrays like array + array => array select array_append(array, array); ERROR: function array_append(integer, integer) does not exist
2
1800
by: JJ Feminella | last post by:
This statement is legal C#: public const string day = "Sunday"; but this statement is not: public const string days = new string { "Sun", "Mon", "Tue" }; The C# Programmer's Reference...
4
1125
by: Randall Arnold | last post by:
My application addes or deletes tab pahes at the user's discretion. On each tab page are controls that must be duplicated. Here's a sample of my code: chart_tabcontrol.TabPages.Add(1)...
0
358
by: Ed Huntress | last post by:
<testtest505050@googlemail.comwrote in message news:f9999f4b-bbd6-4a7e-a0d3-8329e9d4f608@f40g2000pri.googlegroups.com... The night we waved goodbye to America <snip>
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7464
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...
0
5586
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,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
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...
0
3171
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...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.