What is the actual memory cost of storing an integer?

lets say I just do this

$arr = array();
for ($i = 0; $i < 10; $i++) $arr[] = $i;

So I store 10 integers in an array. If the integer is a 32b one, the memory cost should be 40 bytes. Problem is, I didn't tell php that it is an integer so it either has to store it as something else? (js likes to make doubles for example) or keep extra data to remind itself what it is? How much memory do those 10 numbers + the array actually take up in system memory?

Its important since I'm trying to assess the viability of an algorithm I'd like to port to php and its kinda heavy on the memory.

This is a union type, meaning it can store values of multiple types. So yes, it keeps extra data to remind itself what it is. Integers are usually represented as longs (32 or 64 bit depending on your platform).

The above numbers will vary depending on your operating system, your compiler and your compile options. E.g. if you compile PHP with debug or with thread-safety, you will get different numbers. But I think that the sizes given above are what you will see on an average 64-bit production build of PHP 5.3 on Linux.

The numbers above also depend on which version of PHP you are using. The memory footprint of PHP >= 7 should be much lower than for any PHP < 7 due to internal changes to the Zend Engine. See these two blog posts for details: