Solved

Php arrays values

Posted on 2011-02-13
4
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

751 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