array_fill() 用給定的鍵值填充陣列
引數 index 必須。規定返回陣列的起始索引。引數 number 必須。規定填充的元素的數量,其值必須大於0。
引數 value 必須。規定用於填充陣列的鍵值。
<?php
$a1=array_fill(3,4,"blue");
$b1=array_fill(0,1,"red");
print_r($a1);
echo "
"; print_r($b1);
?>
//輸出
array ( [3] => blue [4] => blue [5] => blue [6] => blue )
array ( [0] => red )
array_fill_keys() 用給定的指定鍵名的鍵值填充陣列<?php
$keys=array("a","b","c","d");
$a1=array_fill_keys($keys,"blue");
print_r($a1);
?>
//輸出
array ( [a] => blue [b] => blue [c] => blue [d] => blue )
array_filter() 用**函式過濾陣列中的元素該函式把輸入陣列中的每個鍵值傳給**函式。如果**函式返回true,則把輸入陣列中的當前鍵值返回給結果陣列。陣列鍵名保持不變。
<?php
function test_odd($var)
$a1=array("a","b",2,3,4);
print_r(array_filter($a1,"test_odd"));
?>
//輸出
array ( [3] => 3 )
array_flip()反轉/交換陣列中的鍵名和對應關聯的鍵值
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>
//輸出
array ( [red] => a [green] => b [blue] => c [yellow] => d )
array_intersect()用於比較兩個(或更多個)陣列的鍵值,並返回交集。
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
print_r($result);
?>
//輸出
array ( [a] => red [b] => green [c] => blue )
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");
$result=array_intersect($a1,$a2,$a3);
print_r($result);
?>
//輸出
array ( [a] => red )
array_intersect_assoc()用於比較兩個(或更多個)陣列的鍵名和鍵值,並返回交集
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","c"=>"blue");
$result=array_intersect_assoc($a1,$a2);
print_r($result);
?>
//輸出
array ( [a] => red [b] => green [c] => blue )
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","g"=>"blue");
$a3=array("a"=>"red","b"=>"green","g"=>"blue");
$result=array_intersect_assoc($a1,$a2,$a3);
print_r($result);
?>
//輸出
array ( [a] => red [b] => green )
array_intersect_key()用於比較兩個(或更多個)陣列的鍵名,並返回交集
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","c"=>"blue","d"=>"pink");
$result=array_intersect_key($a1,$a2);
print_r($result);
?>
//輸出
array ( [a] => red [c] => blue )
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("c"=>"yellow","d"=>"black","e"=>"brown");
$a3=array("f"=>"green","c"=>"purple","g"=>"red");
$result=array_intersect_key($a1,$a2,$a3);
print_r($result);
?>
//輸出
array ( [c] => blue )
array_intersect_uassoc()比較兩個(或更多)陣列的鍵名和鍵值(使用使用者自定義函式比較鍵名),並返回交集.
<?php
function myfunction($a,$b)
return ($a>$b)?1:-1;
}$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("d"=>"red","b"=>"green","e"=>"blue");
$result=array_intersect_uassoc($a1,$a2,"myfunction");
print_r($result);
?>
//輸出
array ( [b] => green )
array_intersect_ukey()比較兩個(或更多)陣列(使用使用者自定義函式比較鍵名),並返回交集。
<?php
function myfunction($a,$b)
return ($a>$b)?1:-1;
}$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"blue","b"=>"black","e"=>"blue");
$result=array_intersect_ukey($a1,$a2,"myfunction");
print_r($result);
?>
//輸出
array ( [a] => red [b] => green )
Web API 第二部分
web api 第二部分 元素偏移量 offset element.offsettop element.offsetleft element.offsetwidth 可以得到元素的大小 寬度和高度 是包含padding border width element.offsetheight elemen...
redux 第二部分
redux 的使用方法,為什麼使用 action.js 檔案,進行優化 將其分開,然後我們通過工廠函式的每次返回不同的物件,由於引數是固定的,每次返回的都是事件型別和事件資料,所以我們可以使用乙個函式,通過其返回值來返回乙個物件,讓後傳遞給 action 我們的 reducer 函式有兩個引數,引數...
實驗二 第二部分
第二部分 ftp協議分析 1.兩個同學一組,a和b。2.在a主機上架設ftp伺服器 3.在b主機上執行wireshark,並登陸a主機的ftp伺服器,上傳一張,得到抓取的資料報,4.進行追蹤tcp流,顯示為原始資料,分析得到a主機登陸ftp的過程及使用者名稱密碼,還原上傳的,第二部分 ftp協議分析...