我目前正在编写一个密钥密码函数,以便稍后通过单元测试进行测试。我是PHP的新手,我正在努力从同一个类调用一个函数。这是代码:
<?php
class Code{
public function keyCipher($code){
$alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$alphArr = str_split($alphabet);
$codeArr = str_split($code);
$cipher = array();
$counter = 0;
foreach($codeArr as &$char1){
foreach($alphArr as &$char2){
if($char1 == $char2){
if(!in_array($char1, $cipher)){
$cipher[$counter] = $char1;
$counter++;
}
}
}
}
foreach($alphArr as &$char1){
if(!in_array($char1, $cipher)){
$cipher[$counter] = $char1;
$counter++;
}
}
return implode($cipher);
}
function cipherSolution($keyword, $code){
$this -> keyCipher($keyword);
return $cipher;
}
}
?>
我认为这与 - &gt;有关。运营商,但我不确定它是如何运作的。
WKR
答案 0 :(得分:1)
如果要从keyCipher()返回值,请尝试:
function cipherSolution($keyword) {
return $this->keyCipher($keyword);
}