sub() public method

Subtracts an array, NumArray or numeric value from the existing NumArray
Since: 1.0.0
public sub ( mixed $subtrahend )
$subtrahend mixed an other int, float, array or NumArray
Exemplo n.º 1
0
 /**
  * Tests if cache will be flushed after use of NumArray::sub
  */
 public function testSubCache()
 {
     $numArray = new NumArray(5);
     $numArray->setCache('key', 7);
     $numArray->sub(3);
     $this->assertFalse($numArray->inCache('key'));
 }
Exemplo n.º 2
0
    private function receiveText($object)
    {
        $keyword_raw = trim($object->Content);
        $str_key = mb_substr($keyword_raw, 0, 2, "UTF-8");
        $keyword = mb_substr($keyword_raw, 2, mb_strlen($keyword_raw) - 2, "UTF-8");
        if ($keyword_raw == "博主真帅") {
            $result = $this->transmitText($object, "谢谢夸奖。。不过我好像记错了。。。回复“帮助”查看帮助。。");
            return $result;
        }
        if ($keyword_raw == "主页君照片") {
            $result = $this->transmitText($object, '<a href="http://pic4.nipic.com/20091206/3688710_225859078487_2.jpg">点此查看主页君照片</a>');
            return $result;
        }
        if ($keyword_raw == "关于平台") {
            $content = json_decode('[{
								"Title": "关于平台",
								"Description": "关于本平台的一切",
								"PicUrl": "http://mmbiz.qpic.cn/mmbiz/9p8h2H28HOmAbjeSichfxCpLZt5Y4icvaicuwwf6JCXkVKvhVhVveuad1q4WD2FMOALOrCJNHQ2wA7unGvFpZufRw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1",
								"Url": "http://mp.weixin.qq.com/s?__biz=MzA3NDY5MDQ0OQ==&mid=401351136&idx=1&sn=2dbcbde7a50df32f5af8917c703d5d48&scene=4#wechat_redirect"
							}]', true);
            $result = $this->transmitNews($object, $content);
            return $result;
        }
        if ($keyword_raw == "帮助") {
            $result = $this->transmitText($object, "回复天气+城市名(如“天气北京”)查看本地天气预报\n回复翻译+词汇(如“翻译你好”)查看中译英\n回复英文单词(如“hello”)查看英译中(注:若有标点,请在前加翻译二字。)\n回复“关于平台”查看本平台详细信息\n回复“新闻”查看新闻\n回复菜名,如“鱼香肉丝”查看菜谱\n普通回复,将会召唤出图灵机器人与您聊天。\n回复邮件+内容(如“邮件主页君你好帅”)为主页君发送邮件,最好在邮件内容中附上你的邮箱方便主页君尽快联系您。");
            return $result;
        }
        if ($str_key == '计算') {
            if (strstr($keyword, "[")) {
                $input = explode("#", $keyword);
                if (sizeof($input) == 2) {
                    eval('$array1 = ' . $input[0] . ';');
                    $matrix1 = new NumArray($array1);
                    if (trim($input[1]) == "inv") {
                        $matrix1 = LinAlg::inv($matrix1);
                    }
                    if (trim($input[1]) == "det") {
                        $matrix1 = LinAlg::det($matrix1);
                    }
                } elseif (sizeof($input) == 3) {
                    eval('$array1 = ' . $input[0] . ';');
                    eval('$array2 = ' . $input[2] . ';');
                    $matrix1 = new NumArray($array1);
                    $matrix2 = new NumArray($array2);
                    if (trim($input[1]) == "+") {
                        $matrix1->add($matrix2);
                    }
                    if (trim($input[1]) == "-") {
                        $matrix1->sub($matrix2);
                    }
                    if (trim($input[1]) == "*") {
                        $matrix1->dot($matrix2);
                    }
                }
            } else {
                eval('$matrix1 = ' . $keyword . ';');
            }
            $output = (string) $matrix1;
            if ($matrix1 == 0) {
                $output == "0.000000000001";
            }
            $result = $this->transmitText($object, $output);
            return $result;
        }
        if ($str_key == "天气") {
            $url = "http://apix.sinaapp.com/weather/?appkey=" . $object->ToUserName . "&city=" . urlencode($keyword);
            $output = file_get_contents($url);
            $content = json_decode($output, true);
            $result = $this->transmitNews($object, $content);
            return $result;
        }
        if ($str_key == "邮件") {
            //引入发送邮件类
            require "smtp.php";
            //使用163邮箱服务器
            $smtpserver = "smtp.163.com";
            //163邮箱服务器端口
            $smtpserverport = 25;
            //你的163服务器邮箱账号
            $smtpusermail = "*****@*****.**";
            //收件人邮箱
            $smtpemailto = "*****@*****.**";
            //你的邮箱账号(去掉@163.com)
            $smtpuser = "******";
            //SMTP服务器的用户帐号
            //你的邮箱密码
            $smtppass = "";
            //SMTP服务器的用户密码
            //邮件主题
            $mailsubject = date("m-d") . "意见反馈";
            //邮件内容
            $mailbody = $keyword;
            //邮件格式(HTML/TXT),TXT为文本邮件
            $mailtype = "TXT";
            //这里面的一个true是表示使用身份验证,否则不使用身份验证.
            $smtp = new smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
            //是否显示发送的调试信息
            $smtp->debug = TRUE;
            //发送邮件
            $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
            $result = $this->transmitText($object, "成功发送邮件!");
            return $result;
        }
        if ($str_key == "翻译") {
            $content = $this->baiduDic($keyword);
            $result = $this->transmitText($object, $content);
            return $result;
        }
        if (preg_match("/^[a-zA-Z\\s]+\$/", $keyword_raw)) {
            $content = $this->baiduDic($keyword_raw);
            $result = $this->transmitText($object, $content);
            return $result;
        }
        $content = $this->tulingRobot($keyword_raw);
        if (!($content == "")) {
            $result = $this->transmitText($object, $content);
        } else {
            $output = $this->tulingRobotNews($keyword_raw);
            $temp = json_encode(array_slice($output, 0, 4));
            $final = json_decode($temp, true);
            $subtemp = mb_substr($temp, 0, 1022, "utf-8");
            $result = $this->transmitNews($object, $final);
        }
        return $result;
    }