Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Php arrays values

Posted on 2011-02-13
4
Medium Priority
?
278 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 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

730 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