Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Php arrays values

Posted on 2011-02-13
4
Medium Priority
?
280 Views
Last Modified: 2012-05-11
hi, i have this function but im having a little problem getting the values of arrays:

function hour(){

	
return array(array('value'=>9,'title'=>'9:00 to 11:00 A.M'),array('value'=>11,'title'=>'11:00 to 1:00 P.M'),array('value'=>13,'title'=>'1:00 to 3:00 P.M'),array('value'=>15,'title'=>'3:00 to 6:00 P.M'));
}

function get_delay_hours(){

$hour_options=hour();

if (($hour_options["value"]==9) && ($hour_options["value"]==11) && ($hour_options["value"]==13)){
$delay=-1;
}elseif ($hour_options["value"]==15){
$delay=-2;
}else{
$delay=-3;
}
return $delay;
}

Open in new window

0
Comment
Question by:jd_18286
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 34885616
Your hour() returns a multi-dimensional array. You need to specify the indices of the elements you are trying to dereference:
function hour(){
     return array(
     	array('value'=>9,'title'=>'9:00 to 11:00 A.M')
     	,array('value'=>11,'title'=>'11:00 to 1:00 P.M')
     	,array('value'=>13,'title'=>'1:00 to 3:00 P.M')
     	,array('value'=>15,'title'=>'3:00 to 6:00 P.M')
     	);
}

function get_delay_hours(){

	$hour_options=hour();

	if (($hour_options[0]["value"]==9) && ($hour_options[1]["value"]==11) && ($hour_options[1]["value"]==13)){
		$delay=-1;
	}elseif ($hour_options[3]["value"]==15){
		$delay=-2;
	}else{
		$delay=-3;
	}
return $delay;
}

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34887369
If you can tell us in simple, non-technical terms what this piece of code is supposed to do, I think we might be able to show you a better design.  PHP has a lot of built-in DATETIME processing routines, and life is almost always easier if we use the built-in functions.

This article might be helpful if you are looking for some ideas about handling date and time.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 

Author Closing Comment

by:jd_18286
ID: 35191059
i
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35195058
Once again, I must ask, Please tell us in simple, non-technical terms what you were trying to do and explain how the accepted answer provided a solution to your problem, thanks.  I do not understand either the question or how the solution contributes to the PAQ.  I'm fairly sure there is a good explanation and I think you would do all of us a favor if you offered it up now.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question