php常用单词语法

时间:2021-12-09 11:43:14
header("Content-type:text/html;charset=utf-8");
加入数组array_push($ratings_store_cop,$value);

合并数组:
$a = array(
    '123'=>'111',
    '456'=>'222'
);
$b['123'] = 333;
$a = array_merge($a,$b);
p($a);
返回如下:
Array
(
    [0] => 111
    [1] => 222
    [2] => 333
)
$pid = implode(',',$pid);
$str = "'".implode("','", $str)."'";

$sql = "select * from product where id = $id";
$query = $this->db->query($sql);

$data_db = $query->result_array();$query->free_result();
return $query->row();
return $query->result_array();
return $query->num_rows();

foreach($data_db as $key => $value){

}
$str = "Hello world. I love Shanghai!";
print_r (explode(" ",$str));
// 替换空格,去掉收尾空格$value_trim = str_replace(array(' '),'',trim($value));
// $date = date('Y-m-d',time());
$date = date('Y-m-d H:i:s',time());
$date = date('Y-m-d',strtotime("+8 hour"));
// 替换中文逗号,去掉收尾空格,去掉收尾逗号$skustr = ltrim(rtrim(str_replace(array(','),',',trim($skustr)),','),',');
// 查找$value种_20的位置,再通过substr截取$limit_time = (int)substr($value,strrpos($value,'_20')+1,-4);
// end()
foreach($PurchaseBill as $v){
    $i = 1;
    if($xu_arr[$v['productid']]){
        $i = end($xu_arr[$v['productid']])+1;
    }
    $xu_arr[$v['productid']][] = $i;
}

// 延伸
$people = array("Bill", "Steve", "Mark", "David");

echo current($people) . "<br>"; // 当前元素是 Bill
echo next($people) . "<br>"; // Bill 的下一个元素是 Steve
echo current($people) . "<br>"; // 现在当前元素是 Steve
echo prev($people) . "<br>"; // Steve 的上一个元素是 Bill
echo end($people) . "<br>"; // 最后一个元素是 David
echo prev($people) . "<br>"; // David 之前的元素是 Mark
echo current($people) . "<br>"; // 目前的当前元素是 Mark
echo reset($people) . "<br>"; // 把内部指针移动到数组的首个元素,即 Bill
echo next($people) . "<br>"; // Bill 的下一个元素是 Steve

print_r (each($people)); // 返回当前元素的键名和键值(目前是 Steve),并向前移动内部指针
// 替换字符串的空白
$skustr = preg_replace("'([\r\n])[\s]+'","",$rule_skustr);

// 替换换行符
http://bbs.csdn.net/topics/390239128
//sku进行排序
// $arr = array("aa", "ab", "bz");
// sort($arr);
// p($arr);
// exit;

//读取不同元素
// $a = array('1','2','3');
// $b = array('1','2','3','4');
// $b = array('5');//
// $c = array_merge(array_diff($a,$b),array_diff($b,$a));
// p($c);
// exit;

//合并数组
// $a = array();//
// $a = array('1','2','3');
// $b = array('1','2','3','4');
// $c = array_merge($a,$b);
// p($c);
// exit;
// 反转数组
$arr = array_reverse($arr);
ksort($store_g);//根据键名排序
//合并数组(保留键名且不合并重复)
public function array_add($a1,$a2){
    $n = 0;
    foreach ($a1 as $key => $value) {
        $re[$n] = $value; $n++;
    }
    foreach ($a2 as $key => $value) {
        $re[$n] = $value; $n++;
    }
    return $re;
}

public function array_add2($a1,$a2){
    $a = array("a" => "avalue", "b" => "bvalue");
    $b = array("c" => "cvalue", "d" => "dvalue");
    $c = array();
    foreach( $a as $key => $value ) {
        $c[$key] = $value;
    }
    foreach( $b as $key => $value ) {
        $c[$key] = $value;
    }
    return $c;
}

public function array_add3($a,$b){    // $a = array("a" => "avalue", "b" => "bvalue");    // $b = array("c" => "cvalue", "d" => "dvalue");    $c = array();    foreach( $a as $key => $value ) {        $c[$key] = $value;    }    foreach( $b as $key => $value ) {        $c[$key] = $value;    }    return $c;}
//////////////