<script>ec(2);</script>
http://topic.111cn.net/u/20071202/16/e53996de-4725-4dfa-bf14-c197afeed93c.html
php
class engage
{
public function getArray()
{
$arr1 = array (
''0'' => array (''fid'' => 1, ''tid'' => 1, ''name'' => ''Name1'' ),
''1'' => array (''fid'' => 1, ''tid'' => 2 , ''name'' => ''Name2'' ),
''2'' => array (''fid'' => 1, ''tid'' => 5 , ''name'' => ''Name3'' ),
''3'' => array (''fid'' => 1, ''tid'' => 7 , ''name'' => ''Name4'' ),
''4'' => array (''fid'' => 3, ''tid'' => 9, ''name'' => ''Name5'' )
);
$arr2 = array();
foreach ($arr1 as $key => $value)
{
$arr2[$value[''fid'']][] = array(''tid'' => $value[''tid''],''name'' => $value[''name'']);
}
return $arr2;
}
//print_r($arr2);
//$eString = ''open_door'';
public function getString($eString = null)
{
$eString = explode(''_'',$eString);
$eString = array_map("ucfirst",$eString);
$eString = implode($eString,'''');
return $eString;
}
/**
* 冒泡排序
* @return unknown
*/
public function getBubble()
{
$isOver = false;
$bubbleArray = array(10,2,36,14,10,25,23,85,99,45);
$bubbleResult = $bubbleArray;
do{
$bubbleArray = $bubbleResult;
$isOver = true;
foreach ($bubbleArray as $key => $value)
{
if ($value $bubbleResult[$key-1])
{
$bubbleResult[$key]=$bubbleResult[$key-1];
$bubbleResult[$key-1]=$value;
$isOver = false;
}
}
}while (!$isOver);
return $bubbleResult;
}
}
$engage = new engage();
print_r($engage->getArray());
echo $engage->getString(''make_by_id'');
print_r($engage->getBubble());
?>
pre>
php
/**
* 第二题正则替换实现.
*
*/
function getString($eString = null)
{
$eString = preg_replace(array("/(^[a-z]{1}|_[a-z]{1})/e",''/_/''),
array("strtoupper(''1'')",''''),
$eString);
return $eString;
}
?>