How to include dateInterval property within a variable

Asked

Viewed 70 times

1

After getting the time difference between two fields input time (vine this question), I don’t know now how to put these values within variables, so I can use them in other functions.

The var_dump of the variable $intervalo (who guards the dateInterval) is:

Object(Dateinterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(5) ["i"]=> int(18) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_dayweek_relative"]=> int(0) ["have_special_relative"]=> int(0) }

(in bold above are the fields that matter)

So I tried something like:

$hora = $intervalo[h]; 

or

$hora = $intervalo["h"];

or

$hora = $intervalo['h'];

But I think [h] is not a vector... The question is: how to put the property [h] in a variable?

I searched the manual page, but my English is not there these things, so did not solve.

1 answer

2


First word of var_dump shows object then to access its properties use the arrow operator ->.

can obtain the value as follows:

$hora = $intervalo->h;

or:

$hora = $intervalo->format('diferença de horas: %h');

List of parameters valid for format

  • Perfect, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.