<?php
/**
* VECTOR COOL
* https://vector.cool
* 去除值為"ccc"的元素
*/
$arr=array(1=>'aaa',2=>'bbb',3=>'ccc');
unset($arr[array_search('ccc',$arr)]); //按元素值返回鍵名。去除後保持索引
print_r($a);
?>參考:
[……]
$str = ‘測試字串’;
$fp = fopen(‘ftp://username:[email protected]/test.txt’,’w’);
fwrite($fp, $str);
fclose($fp);[……]
$str = ‘測試字串’;
$fp = fopen(‘text.txt’,’w’);
fwrite($fp, $str);
fclose($fp);
fopen()參數說明
[……]
$(document).ready(function(e) {
$('#test').click(function(e){
alert('觸發綁定事件');
});
$('#test').trigger("click");
$('#test')[0].click;
});http://www.pureexample.com/tw/jquery/custom-event.html[……]
/**
* VECTOR COOL
* https://vector.cool
*/
//用curl傳post並取回傳值
//一定要傳絕對路徑
function curl_post($url,$post)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close ($ch);
return $result;
}/** * VECTOR COOL * https://vector.cool */ $url='http://tw.yahoo.com'; $post_value= array( 'name' => 'JACK', 'age' => '20', 'phone' => '0968123456', 'address' => '台灣' ); echo curl_post($url,$post_value);
[……]
/* 找不到 */
SELECT * FROM news WHERE class = NULL
/* 找不到 */
SELECT * FROM news WHERE class IN ( 0 , 1 , NULL )
/* 要這樣寫 */
SELECT * FROM news WHERE class IS NULL[……]
// 方法1
var datastring = $("#form").serialize();
$.ajax({
type: "POST",
url: "test.php",
data: datastring,
success: function(data) {
alert('Data send');
}
});
//方法2
var form = $(this).closest('form');
var data = form.serializeArray();
data.push({name: "fun", value: 'img_edit'}); //增加自訂的值
data.push({name: "time", value: $.now()}); //增加自訂的值data = $.param(data);
$.ajax({
type: "POST",
url: "test.php",
data: data,
success: function(data) {
alert('Data send');
}
});test.php 測試
<?php
print_r($_POST);
exit;
?>
結果
Array (
[mail] => [email protected]
[password] => asdfasdf
[name] => test
[sex] => 1
)
https://api.jquery.com/serialize/
[……]