如何把python程序转化为php程序??

defgetxued():'''获取学段数据并存入redisxueduan:list和xueduanlistObj'''try:sql="SELECTid,name,fi... def getxued(): '''获取学段数据并存入redis xueduan:list 和 xueduan list Obj ''' try: sql = "SELECT id,name,fid FROM `wl_class` \ WHERE fid=%s" cursor.execute(sql, (39778)) # Fetch all the rows in a list of lists. results = cursor.fetchall() rdb.delete("xueduan:list") for row in results: did = row[0] name = row[1] fid = row[2] rdb.rpush("xueduan:list",did) xueduan.append(did) # Now print fetched result print("xueduan : did=%d,name=%s,fid=%d" % \ (did, name, fid )) except Exception as e: print (str(e))
我想把上边的python转化为相应的php程序??
展开
 我来答
百度网友2f757675
2016-09-13 · TA获得超过7233个赞
知道大有可为答主
回答量:7506
采纳率:90%
帮助的人:1934万
展开全部
<?php
class FrogCrossRiver{
var $cur = array();
var $end = array();

function getPossibleMove($cur){
$lst = array();
$zeroIdx = array_search(0,$cur);

if ($zeroIdx-1>=0 && $cur[$zeroIdx-1]==1){ #left 1
$lst[$zeroIdx-1] = 1;
}
if ($zeroIdx-2>=0 && $cur[$zeroIdx-2]==1){ # left 2
$lst[$zeroIdx-2] = 2;
}
if ($zeroIdx+1<=6 && $cur[$zeroIdx+1]==2){ # right 1
$lst[$zeroIdx+1] = -1;
}
if ($zeroIdx+2<=6 && $cur[$zeroIdx+2]==2){ # right 2
$lst[$zeroIdx+2] = -2;
}
return $lst;
}

function printStep($myStep){
$tmp = $this->cur;
echo "===========================<br/>";
foreach ($myStep as $v){
foreach ($v as $idx => $mv){
$tt = $tmp[$idx];
$tmp[$idx] = $tmp[$idx + $mv];
$tmp[$idx+$mv] = $tt;
echo "cur[{$idx}] move {$mv} <br/>";
echo " [" . implode(',', $tmp) . "]<br/>";
}
}
echo "===========================<br/>";
}

function jump($cur,$myStep){
#print_r($cur); echo "<br/>";
if (array_intersect($cur, $this->end)==$this->end){
$this->printStep($myStep);
return;
}
$lst = $this->getPossibleMove($cur);
foreach ($lst as $idx => $mv){
$newCur = $cur;
$newMyStep = $myStep;
$newMyStep[] = array($idx=>$mv);
$tt = $newCur[$idx];
$newCur[$idx] = $newCur[$idx + $mv];
$newCur[$idx+$mv] = $tt;
$this->jump($newCur,$newMyStep);
}
}

function doit(){
$this->cur = array(1,1,1,0,2,2,2);
$this->end = array(2,2,2,0,1,1,1);
$this->jump($this->cur, array());
}
}
# Start
$f = new FrogCrossRiver();
$f->doit();
?>

这样就可以了,在php网页的环境下执行即可看到和python一样的输出效果。
追问
这貌似和我上边的python程序没什么太大的关联啊???
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式