473,468 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Arrays and Complex Indices

Hi...
the following line doesn't give its intended effect
$selected[ $out['month'] ] = 'SELECTED';

but this line will:
$selected[ $out['month'] + 0 ] = 'SELECTED';

How do I make sure $out['month'] is evaluated correctly without added a
0 to guide php?

thanks

Jul 17 '05 #1
5 1241

<bi*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi...
the following line doesn't give its intended effect
$selected[ $out['month'] ] = 'SELECTED';

but this line will:
$selected[ $out['month'] + 0 ] = 'SELECTED';

How do I make sure $out['month'] is evaluated correctly without added a
0 to guide php?

thanks


what do you get for
print_r($out)

and
print_r($selected)

and how do you populate the arrays in the first place?

Matt
Jul 17 '05 #2
$out:
Array ( [course_id] => [html_title] => Change Profile [trail] => Home >
Change Profile:

[hooks] => Back to Home [day] => 12 [month] => 05 [year] => 1983
[birmonth] => )

1

$selected

Array ( [1] => [2] => [3] => [4] => [5] => SELECTED [6] => [7] => [8]
=> [9] => [10] => [11] => [12] => )

1

Jul 17 '05 #3

<bi*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
$out:
Array ( [course_id] => [html_title] => Change Profile [trail] => Home >
Change Profile:

[hooks] => Back to Home [day] => 12 [month] => 05 [year] => 1983
[birmonth] => ) $selected

Array ( [1] => [2] => [3] => [4] => [5] => SELECTED [6] => [7] => [8]
=> [9] => [10] => [11] => [12] => )


Right, got it.

When PHP looks at $selected[$out['month']], it evaluates $selected['05'] by
the looks of it, i.e. the 'month' value in $out is a string, not a number.
To fix this, try either
1 - set the value as a number in the first place:
$out['month'] = 5;

2 - cast the value to an integer
$selected[int($out['month']] = 'SELECTED';

Hope this helps

Matt
Jul 17 '05 #4
"Matt Mitchell" <m_****************************@metalsponge.net> wrote in
message news:uK*******************@fe3.news.blueyonder.co. uk...
2 - cast the value to an integer
$selected[int($out['month']] = 'SELECTED';


Should be $selected[(int) $out['month']]. int() is a function called "int".
Jul 17 '05 #5

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Xt********************@comcast.com...
"Matt Mitchell" <m_****************************@metalsponge.net> wrote in
message news:uK*******************@fe3.news.blueyonder.co. uk...
2 - cast the value to an integer
$selected[int($out['month']] = 'SELECTED';


Should be $selected[(int) $out['month']]. int() is a function called
"int".


Good point. Wasn't thinking.

Matt
Jul 17 '05 #6

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

Similar topics

7
by: seia0106 | last post by:
Hello, Writing a program in c++ that should use complex numbers I have two choices before me. 1- define a struct for complex data i.e struct {float real,imag; }ComplexNum; 2-use an array...
46
by: Blue Ocean | last post by:
How do I do it? I'm doing a practice problem which includes me implementing a set of ints as a class. I don't want to use vector because that would be cheating. ;) I don't want to spend...
5
by: Cant Think Today | last post by:
I have multi-dimesional arrays that can be specifed by the user, e.g 1,2,3,4,5 1,2,3,4,5,6,7,8,9,10 1,2,3,4,5,6 I think a bit of code that will iterate over these arrays to print out the...
6
by: hoover_richard | last post by:
I am a newbie to C++ and I need help with a simple program I am trying to write. My program is designed to print all of the odd integers contained in an array and output the sum of the odd...
34
by: Christopher Benson-Manica | last post by:
If an array is sparse, say something like var foo=; foo=4; foo='baz'; foo='moo'; is there a way to iterate through the entire array? --
1
by: seia0106 | last post by:
Hello, I have an array X=, whose even and odd indices should represent real and imaginary parts of complex numbers. This I want to use in a routine that uses the typedef double Cx; for storing...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
3
by: J.M. | last post by:
I have data in a double array of length 2N, which actually represents complex numbers with real and imaginary parts interlaced. In other words, elements in this array with even indices represents...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.