我已经声明了一个反转整个句子的函数:
<?php
class String {
private $error;
private $length;
private $string = "";
private $array = array();
private $index = 0;
private $indexOf = false;
private $word;
private $str;
public function __construct($string="") {
$this->string = $string;
}
public function revers_sentence() {
$this->string = strrev($this->string);
return $this;
}
...但是如何声明一个类函数来反转一个句子的第一个单词中的字母?
public function revers_1_word() {
hmm ?
}
答案 0 :(得分:2)
您为此声明方法如下:
public function reverse_first_word() {
// Insert your implementation here.
}
: - )
答案 1 :(得分:1)
public function reverse_1_word() {
$str_words = explode(" ", $this->string);
$str_words[0] = strrev($str_words[0]);
$this->string = implode(" ", $str_words);
return $this;
}