PHP code example of nancheng / pfinal-array
1. Go to this page and download the library: Download nancheng/pfinal-array library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nancheng / pfinal-array example snippets Array
e pf\arr\PFarr;
// 调用方法
$arr = [1,54,'a',45,12,'c',1,1,12,[1,1,'a',['a','b','a']]];
$arr = PFarr::pf_array_unique($arr);
echo '<pre>';
print_r($arr);
// 结果
Array
(
[0] => 1
[1] => 54
[2] => a
[3] => 45
[4] => 12
[5] => c
[9] => Array
(
[0] => 1
[2] => a
[3] => Array
(
[0] => a
[1] => b
)
)
)
$result = PFarr::pf_array_col($records, 'first_name', 'id');
print_r($result);
$records = [
[
'city' => '上海',
'age' => 18,
'name' => '马二'
],
[
'city' => '上海',
'age' => 20,
'name' => '翠花'
]
];
//按照 city 分组
$arr = PFarr::pf_array_group_by($records,'city');
//按照 city 分组 完成 之后 再按照 age 分组
$arr1 = PFarr::pf_array_group_by($records,'city','age');
//组词算法
$arr=array('裤子','牛仔','低腰','加肥');
$count=count($arr);
for($i=1;$i<=$count;$i++){
$temp[$i]=PFarr::pf_diy_words($arr,$i);
}
PFarr::dd($temp);
$arr_one = ['a','b','c','d'];
$arr_two = ['a','b','a','c','b','d'];
PFarr::dd(PFarr::pf_count_element($arr_one));
/*
返回
Array
(
[a] => 1
[b] => 1
[c] => 1
[d] => 1
)
*/
PFarr::dd(PFarr::pf_count_element($arr_two));
/*
返回
Array
(
[a] => 2
[b] => 2
[c] => 1
[d] => 1
)
*/
$array = [
['id' => '123', 'name' => 'aaa', 'class' => 'x'],
['id' => '124', 'name' => 'bbb', 'class' => 'x'],
['id' => '345', 'name' => 'ccc', 'class' => 'y'],
];
PFarr::dd(PFarr::pf_map($array,'id','name'));
/*
返回:
Array
(
[123] => aaa
[124] => bbb
[345] => ccc
)
*/
PFarr::dd(PFarr::pf_map($array,'id','name','class'));
/*
返回
Array
(
[x] => Array
(
[123] => aaa
[124] => bbb
)
[y] => Array
(
[345] => ccc
)
)
*/