How to convert SimpleXMLElement attribute to string

I have a SimpleXMLElement and what I want to do is use one of its attributes as an array index:

$element = $xml->path->to->element;

$array = array();
$attribute = $element['attribute'];
$array[$attribute] = 'yadayada';

I get ‘Illegal offset type’ error. Is it somehow possible to convert the element attribute to string?

Thank you.

Not sure if this will help you but you can typecast

$var = (string) $var;

Thanks that worked, I forgot typecasting works in PHP.