Some of the problems may not be well described. I will give you a simple example of {code...}. The above method can meet my needs. What other methods can be implemented? I found a built-in function array_chunk ($ arr, 1, true), but this key name cannot be set. The problem may not be well described. Let me give you a simple example.
// Requirement $ arr = array ('20160301', '20160301', '20160301', '20160301', '20160301 '); $ newArr = array ('id' => '123'), array ('id' => '123 '), array ('id' => '20140901'), array ('id' => '20160901'), array ('id' => '20160901 '), array ('id' => '000000'); // my processing method is $ newArr = []; foreach ($ arr as $ val) {$ newArr [] = array ('id' => $ val );}
The above method can meet my needs. What other methods can be implemented? I found a built-in function.array_chunk($arr, 1, true)
However, this key name cannot be set.
Reply content:
The problem may not be well described. Let me give you a simple example.
// Requirement $ arr = array ('20160301', '20160301', '20160301', '20160301', '20160301 '); $ newArr = array ('id' => '123'), array ('id' => '123 '), array ('id' => '20140901'), array ('id' => '20160901'), array ('id' => '20160901 '), array ('id' => '000000'); // my processing method is $ newArr = []; foreach ($ arr as $ val) {$ newArr [] = array ('id' => $ val );}
The above method can meet my needs. What other methods can be implemented? I found a built-in function.array_chunk($arr, 1, true)
However, this key name cannot be set.
The array_map () function can meet your needs:
$ Arr = array ('000000', '000000', '000000', '000000', '000000'); function make ($ v) {return array ('id' => $ v) ;}$ newArr = array_map ('make', $ arr); var_dump ($ newArr ); // thank you for choosing $ newArr = array_map (function ($ v) {return array ('id' => $ v) ;}, $ arr );
In addition, you can use anonymous functions to make them more elegant.