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;

http://www.php.net/manual/en/language.types.string.php#language.types.string.casting

Thanks that worked, I forgot typecasting works in PHP.