Solved

Php arrays values

Posted on 2011-02-13
4
273 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 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

19 Experts available now in Live!

Get 1:1 Help Now