Jump to content

problem with array key !


yami007

Recommended Posts

In this line:

 

$time['hour'] = $hour;

 

You're overwriting the "hour" index in the array on every iteration. I'm guessing you either just want:

 

$time[] = $hour;

 

To have a single dimension array holding the times, or:

 

$time['hour'][] = $hour;

 

If you want the hour index to be an array itself.

You are right I wanted to do something like the latter...but I have minutes too, I want the array to be something like this

 

Array
(
[0] => Array
(
[hour] => 8
[minute] => 0
)
[1] => Array
(
[hour] => 8
[minute] => 45
)
)

 

anyway to do this ?

You can set both at once like:

 

$time[] = array(
    'hour' => $hour,
    'minute' => $minute
);

 

But it kind of depends where you're getting the data from. Using a loop like you are doing is good for the hour, but you then need the minutes. Are you just wanting to generate an array for each hour with 0, 15, 30 and 45 minutes?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.