# PHP MAKES NO SENSE! :( ///// does not work $xpath = '/'; $parts = array('one', 'two', 'three'); foreach($parts as $index => $part){ $xpath .= $parts[$index] . '/'; if($index+1 == strlen($parts)){ $xpath .= 'text()'; } } // $xpath should be /one/two/three/text() ///// works... why? $xpath = '/'; $parts = array('one', 'two', 'three'); foreach($parts as $index => $part){ $xpath .= $parts[$index] . '/'; if($index+3 == strlen($parts)){ $xpath .= 'text()'; } } // $xpath should be /one/two/three/text()