9Algorithm
9Algorithm

Reputation: 1257

What does this PHP syntax mean? Can't find any information in the docs

function get( $str ){
    $matches = $this->xml->xpath("/conf/item [@name= \"$str\"]");
    if (count($matches)) {
    $this->lastmatch = $matches[0];
    return (string) $matches[0];
}

I can't find any information about what the last line of this code does.

What does this (string) $matches[0] piece do?

As I can guess, it returns the zero element of the array as a string. But I didn't find any mention about this syntax in the docs.

Am I right?

And it will be great if you provide me with a link where I can read about this.

Upvotes: 0

Views: 55

Answers (1)

Niki van Stein
Niki van Stein

Reputation: 10724

You can read about it here: http://php.net/manual/en/language.types.type-juggling.php
It is called type juggling, because php does not have explicit types.

You can use the following type castings:

(int), (integer) - cast to integer
(bool), (boolean) - cast to boolean
(float), (double), (real) - cast to float
(string) - cast to string
(array) - cast to array
(object) - cast to object
(unset) - cast to NULL (PHP 5)

Upvotes: 2

Related Questions