Home >Backend Development >PHP Tutorial >微信开发的对象问题
<?phpfunction grade($td_array){ shuffle($td_array); foreach($td_array as $v){ echo "课程:".$v[0]; $score=$v[1]; switch($score) { case $score>=90 && $score<=100: echo " 绩点:4.0 成绩:".$score." <br>"; break; case $score>=80 && $score<90: echo " 绩点:3.0 成绩:".$score." <br>"; break; case $score>=70 && $score<80: echo " 绩点:2.0 成绩:".$score." <br>"; break; case $score>=60 && $score<70: echo " 绩点:1.0 成绩:".$score." <br>"; break; case $score>=0 && $score<60: echo " 绩点:0.0 成绩:".$score." <br>"; break; default: echo $score; } } return ;} $table =" Array ( [0] => 商务英语听说{td}90{td}2.0{td} [1] => 形势与政策(八){td}70{td}0.5{td} [2] => 积极心态训练{td}89{td}1.0{td} [3] => 欧洲旅游产品设计与营销{td}76{td}2.0{td} )"; array_pop($table); foreach ($table as $key=>$tr) { $td = explode('{td}', $tr); array_pop($td); $td_array[] = $td; }$grade=grade($td_array);print_r ($grade);
private function grade($td_array){ shuffle($td_array); foreach($td_array as $v){ echo "课程:".$v[0]; $score=$v[1]; switch($score) { case $score>=90 && $score<=100: echo " 绩点:4.0 成绩:".$score." <br>"; break; case $score>=80 && $score<90: echo " 绩点:3.0 成绩:".$score." <br>"; break; case $score>=70 && $score<80: echo " 绩点:2.0 成绩:".$score." <br>"; break; case $score>=60 && $score<70: echo " 绩点:1.0 成绩:".$score." <br>"; break; case $score>=0 && $score<60: echo " 绩点:0.0 成绩:".$score." <br>"; break; default: echo $score; } } return ; } public function responseMsg() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)){ $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $picTpl = "<xml> <ToUserName><![CDATA[".$fromUsername."]]></ToUserName> <FromUserName><![CDATA[".$toUsername."]]></FromUserName> <CreateTime>".$time."</CreateTime> <MsgType><![CDATA[news]]></MsgType> <ArticleCount>1</ArticleCount> <Articles> <item> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[]]></PicUrl> <Url><![CDATA[]]></Url> </item> </Articles> <FuncFlag>1</FuncFlag> </xml>"; if(!empty( $keyword )) { $table = "Array ( [0] => 商务英语听说{td}90{td}2.0{td} [1] => 形势与政策(八){td}70{td}0.5{td} [2] => 积极心态训练{td}89{td}1.0{td} [3] => 欧洲旅游产品设计与营销{td}76{td}2.0{td} )"; array_pop($table); foreach ($table as $key=>$tr) { $td = explode('{td}', $tr); array_pop($td); $td_array[] = $td; } $content=$this->grade($td_array); $title ="123"; $resultStr = sprintf ( $picTpl,$title,$content); echo $resultStr; } }else{ echo ""; exit; } }
你自己模拟微信请求下面的逻辑,看看输出什么?
多做些记录
你自己模拟微信请求下面的逻辑,看看输出什么?
多做些记录