Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Arrays and Complex Indices

 
   Database Help (Home) -> PHP RSS
Next:  update problem: phpinfo disabled?  
Author Message
bigoxygen

External


Since: Feb 16, 2005
Posts: 2



(Msg. 1) Posted: Wed Feb 16, 2005 11:13 am
Post subject: Arrays and Complex Indices
Archived from groups: comp>lang>php (more info?)

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

 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
bigoxygen

External


Since: Feb 16, 2005
Posts: 2



(Msg. 2) Posted: Wed Feb 16, 2005 11:42 am
Post subject: Re: Arrays and Complex Indices [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

$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

 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
Matt Mitchell

External


Since: Feb 14, 2005
Posts: 39



(Msg. 3) Posted: Wed Feb 16, 2005 4:41 pm
Post subject: Re: Arrays and Complex Indices [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

wrote in message

 > 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
 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
Matt Mitchell

External


Since: Feb 14, 2005
Posts: 39



(Msg. 4) Posted: Wed Feb 16, 2005 4:41 pm
Post subject: Re: Arrays and Complex Indices [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

wrote in message

 > $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
 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
Chung Leong

External


Since: Dec 06, 2003
Posts: 73



(Msg. 5) Posted: Wed Feb 16, 2005 8:01 pm
Post subject: Re: Arrays and Complex Indices [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Matt Mitchell" wrote in
message
 > 2 - cast the value to an integer
 > $selected[int($out['month']] = 'SELECTED';

Should be $selected[(int) $out['month']]. int() is a function called "int".
 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
Matt Mitchell

External


Since: Feb 14, 2005
Posts: 39



(Msg. 6) Posted: Thu Feb 17, 2005 2:40 pm
Post subject: Re: Arrays and Complex Indices [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Chung Leong" wrote in message



  >> 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
 >> Stay informed about: Arrays and Complex Indices 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Problem With Arrays Of Arrays, PHP 5.2.0, Windows - $aThePosts = array_change_key_case($_POST, CASE_LOWER); define("CONTACT_IS_LOCAL", 0); define("CONTACT_IS_REMOTE", 1); /* $aWho contains an array of arrays (contact details) * array( * array(0, CONTACT_IS_LOCAL, "My Local Con...

Indexing non-arrays as arrays, no warnings? - I was a bit surprised to find that indexing some non-arrays as if they were arrays does not even raise a Notice message. This works for NULL, integer, and floats at least. (PHP-5.2.1) error_reporting(E_ALL+E_STRICT); $arry = array(1=>1); $nullv...

debug_backtrace and FILE/LINE indices - Hi all, I've been using debug_backtrace() for a while to provide stack traces for a custom logging function. Today was the first time I've got the following error: "Notice: Undefined index: file in E:\webroot\lib\errors.php on line 341 Notice:..

arrays - Hi! How to create one array that will hold numbers from 3 to 50, their square roots, and number * 10? example: 3, 1.43, 30 4, 2, 40 Thanks

Using arrays - I'm quite new to PHP so please spoone feed me here. I'm trying to generate a list of URLs from a directory to feed into a slideshow but I'm completely stumped as to how to do it. I've been given the following code to generate a list of 15 URLs with the....
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]