PHP operation of two-dimensional array simulation function mysql

PHP操作 二维数组模拟mysql函数
<pre>
public function monimysqltest(){
$testarray=array(
array('ss'=>'1','dd'=>'11'),
array('ss'=>'2','dd'=>'22'),
array('ss'=>'3','dd'=>'33'),
array('ss'=>'4','dd'=>'44'),
);
$sa=$this->arrayfilter($testarray,'ss',array(3,4));
echo'模拟where<br>';
print_r($sa);
echo'<br>';
$array[] = array('id'=>1,'price'=>50);
$array[] = array('id'=>2,'price'=>70);
$array[] = array('id'=>3,'price'=>50);
$array[] = array('id'=>4,'price'=>20);
$arre=$this->arraysort($array,'price',SORT_DESC);
echo'模拟orderby<br>';
print_r($arre);
echo'</br>';

Array AA = $ (
Array ( 'ID' => 123, 'name' => 'John Doe'),
Array ( 'ID' => 123, 'name' => 'John Doe'),
Array ( 'ID' => 124, 'name' = > ' Wang Wu'),
Array ( 'ID' => 125, 'name' => 'Zhao six'),
Array ( 'ID' => 126, 'name' => ' Zhao six ')
);
$ Key =' ID ';
$ BB = $ this-> assoc_unique ($ AA, $ Key);
echo' <br> analog GroupBy ';
print_r ($ BB);

echo 'simulation limit function directly PHParray_slice get <br>';


}

/ * PHP imitate mysql where screening * /

function arrayfilter($arr,$key,$val){
$list=array();
foreach ($arr as $k=>$v){
foreach ($val as $k1=>$v1){
if($v[$key]==$v1){
$list[]=$v;
}
}

}
return $list;
}

/ * PHP dimensional Sort * /
function arraysort ($ arr, $ key1, $ paixu) {

foreach ($arr as $key=>$value){
$price[$key] = $value[$key1];
}

array_multisort($price,$paixu,$arr);
return $arr;
}

 

 

// simulate groupby

function assoc_unique ($ ARR, $ Key) {
$ of arr1 = $ ARR;
$ tmp_arr = Array ();
the foreach ($ ARR AS $ K => $ V) {
IF (the in_array ($ V [$ Key], $ tmp_arr) ) {// search $ v [$ key] $ tmp_arr array are in the presence, if present, returns to true
the unset ($ ARR [K $]);
} the else {
$ tmp_arr [] = $ v [$ key];
}
}
the foreach (ARR $ $ K AS => $ V) {
$ ARR [K $] [ 'Lists'] = $ this-> arrayfilter (of arr1 $, $ Key, Array ($ V [Key $]));
}
return ARR $;
}
</ pre>

 

 

Guess you like

Origin www.cnblogs.com/newmiracle/p/11873111.html