Search code examples
phpdatedatetimeepoch

Remove Type from PHP Array: int(2) => "2"


I am attempting to store a Epoch timestamp as an integer in an a map in PHP, however, I am running into trouble getting the pure integer value, instead getting (int) before the value of the timestamp.

$property = "test property";
$date = new DateTime();
$timestamp = $date->getTimestamp();
$tmpArray = array($property => $timestamp);
var_dump($tmpArray);

$tmpArray has a structure as the following:

array(1) { ["test property"]=> int(1493778589) }

Is there a way to get the value in the map to be just 1493778047 without the (int) before it?


Solution

  • You're misunderstanding the output of var_dump().

    The value you have IS an integer. The int() you see it wrapped in is simply var_dump()'s way of telling you the data type.