![](https://img.imzhp.com/19/images/80fc41e9d98493da579c59715dbc42d7.jpg-web) 直接上代码吧: ```php <?php if($argc>1){ if(function_exists($argv[1])) { $tmp = $argv; array_shift($tmp); array_shift($tmp); call_user_func_array($argv[1], $tmp); exit; } } echo 'php ' . basename(__FILE__) . ' <funcname> <arg1> <arg2>' . PHP_EOL; echo ' funcname: jiujiu, rmb, chefei, findsecnum' . PHP_EOL; //99乘法表 function jiujiu(){ for($i=9;$i>0;$i--){ for($j=9;$j>=$i;$j--){ echo $j . '*' . $i . '=' . ($i*$j) . ' '; } echo PHP_EOL; } } /** * 人民币解析 */ function rmb($num = 123.22) { $rmb = [ '10000' => '100元', '5000' => '50元', '2000' => '20元', '1000' => '10元', '500' => '5元', '100' => '1元', '50' => '5毛', '10' => '1毛', '5' => '5分', '1' => '1分' ]; $str = ''; $num = $num * 100; foreach($rmb as $k => $v) { if($num>$k) { $c = intval($num/$k); $str .= $v . $c . '张'; $num-=$c*$k; } if(!$num) break; } echo $str . PHP_EOL; } function CheFei($start = '香港', $end = '虎门') { if(is_array($start)) { list($start, $end) = $start; } $chepiao = [ [ 'start' => '深圳', 'end' => '广州', 'money' => '60' ], [ 'start' => '广州', 'end' => '虎门', 'money' => '50' ], [ 'start' => '虎门', 'end' => '中山', 'money' => '40' ], [ 'start' => '中山', 'end' => '珠海', 'money' => '36' ], [ 'start' => '珠海', 'end' => '澳门', 'money' => '34' ], [ 'start' => '澳门', 'end' => '香港', 'money' => '89' ], ]; //简单方法,这是个单点的处理,所以只处理一个起点的KEY即可。 $a1 = []; //顺查数组 $a2 = []; //逆查数组 foreach($chepiao as $v) { $a1[$v['start']] = $v; $a2[$v['end']] = $v; } $num = 0; $sk = 'start'; $ek = 'end'; if(isset($a1[$start]) && isset($a2[$end])) { } else if (isset($a2[$start]) && isset($a1[$end])) { $a1 = $a2; $ek = 'start'; $sk = 'end'; } else { echo '起止站点无法查询' . PHP_EOL; exit; } $s1 = $start; $v = $a1[$s1]; $sites = []; while(true) { $num += $v['money']; if($v[$ek] == $end) { break; } $v = $a1[$v[$ek]]; $s1 = $v[$sk]; $sites[] = $s1; if(count($sites)>count($a1)) { break; } } $sites[] = $end; // print_r($sites); echo '从《' . $start . '》到《' . $end . '》共' . count($sites) . '站,需要' . $num . '元' . PHP_EOL; } function findsecnum($arys = []) { $tmp = func_get_args(); if(count($tmp)>1) { $arys = $tmp; } else if(is_string($arys)) { $arys = explode(',', $arys); } if(!$arys) { return; } echo '原数组:'; print_r($arys); arsort($arys); $v = array_values($arys)[1]; echo '第二大的数字是:' . $v . PHP_EOL; echo '在原数组中的KEY是:' . array_search($v, $arys) . PHP_EOL; } ``` 最后修改:4年前 © 著作权归作者所有