0

I have a date that I'm getting from a date picker. It is returning an array() like the following...

array(12) { 
    ["year"]=> int(2016) 
    ["month"]=> int(11) 
    ["day"]=> int(24) 
    ["hour"]=> bool(false) 
    ["minute"]=> bool(false) 
    ["second"]=> bool(false) 
    ["fraction"]=> bool(false) 
    ["warning_count"]=> int(0) 
    ["warnings"]=> array(0) { } 
    ["error_count"]=> int(0) 
    ["errors"]=> array(0) { } 
    ["is_localtime"]=> bool(false) 
}

I tried to get just the month or the year out of this array() utilizing a foreach() but no success with it. How can I iterate through this array() and extract the year or month independently?

9
  • 3
    It's an ordinary associative array, you just use $variable['year'] or $variable['month'] Commented Nov 9, 2016 at 21:02
  • 1
    Why do you think you need to iterate? There aren't multiple dates here. Commented Nov 9, 2016 at 21:03
  • I thought that I have to iterate through the array to get the keys and store the values in variables. Commented Nov 9, 2016 at 21:06
  • Don't you know the key names ? Commented Nov 9, 2016 at 21:06
  • @Gilbert It seems like you have a basic misunderstanding about how associative arrays are used. Commented Nov 9, 2016 at 21:08

1 Answer 1

1

You could pass the array elements through PHP mktime() and will return a UNIX Timestamp.

Doesn't look like a multidimensional array, so you shouldn't have to iterate, just access the key like:

$year = $array['year'];
// etc
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.