473,246 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

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 1235

<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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.