Fixed using resource as array index

Shouldn't use a resource as array index (throws a notice/warning), made it explicit cast