PHP collect some commonly used functions and easy to use custom functions

1 . Custom print function P

 

 

 effect:

 

 2.array_clomn()  和array_combine() 和array_values()

Explanation

array_column ( array $input , mixed $column_key [, mixed $index_key = null ] ) 

array_column () returns inputan array of the key column_keycolumns, if the optional parameter index_key, then the inputvalue of this column in the array will be returned as a value corresponding to the key array.

 

array_combine ( array $keys , array $values ):数组

By using an array of values keysas the key and used  valuesas a corresponding value in the array to  create an array .

 

array_values ​​() function returns a given array comprises an array of all the keys, but do not hold the keys.

Example: $ array ARR have such a:

 

 Remove the like corresponding to the id value array name

$ arr = array_column ($ goods, 'name', 'id');

output

 

 

$arr = array_combine(array_column($arr,'id'),$arr);

The output is

 

Key removed name: $ arr = array_values ​​($ arr) Example scenario (after cycles merge array removed foregoing id keys)

 

Guess you like

Origin www.cnblogs.com/youantianqin/p/11886584.html