Solved

Php arrays values

Posted on 2011-02-13
4
272 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 500 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 108

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 108

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now