thinkphp a two-dimensional array into a label applicable one-dimensional array method summary, thinkphp dimension
This paper summarizes the one-dimensional array method that thinkphp a two-dimensional array into a label. Share to everyone for your reference. The implementation method is as follows:
Method One:
Copy the code as follows: $projectList =arr1tag ($projectList, Array (', ' Please select '), ' project_name ');
Where $list is a two-dimensional array that passes values, $default as the default, $k to the specified table field.
function Arr1tag ($list, $default = ', $k = ') {
$tmp = ";
if (array ($list)) {
if (array ($default)) {
$tmp [$default [0]]= $default [1];
}
foreach ($list as $k 1=> $v 1) {
$tmp [$k 1+1]= $v 1[$k];
}
}
return $tmp;
}
Method Two:
The
copy Code code is as follows: $projectList =arr2tag ($projectList, Array (', ' Please select '), ');
//Get the corresponding value according to the array subscript
function Array_index2val ($array, $index =0) {
$value = ';
if (Is_array ($array)) {
$i = 0;
foreach ($array as $val) {
if ($i = = = $index) {
$value = $val;
break;
}
$i + +;
}
}
return $value;
}
//Converts an array from the database to an array that can use the template label, where $default is the default value, $k the specified table field
function Arr2tag ($arr, $default =null, $K =null) {
$tmp = ';
if (Is_array ($arr)) {
if (Is_array ($default)) {
$tmp [$default [0]]= $default [1];
if ($type ==1) {
$tmp [$default [2]]= $default [3];
}
}
foreach ($arr as $key = $val) {
if (Is_array ($K)) {
$tmp [$val [$K [0]]]= $val [$K [1]];
}else{
$tmp [Array_index2val ($val, 0)]=array_index2val ($val, 1);
}
}
}
return $tmp;
}
Method Three:
Converts the contents of the read database directly into a one-dimensional array, which is mostly used for select labels
Copy the code as follows: $this->where ($where)->getfield (' Id,name ');
The resulting content is
Array
' id ' = ' name ',
)
It is hoped that this article will be helpful to everyone's thinkphp framework design.
How to use the thinkphp program to change such a two-dimensional array to one-dimensional array
Do not understand, your one-dimensional array want to achieve what effect, it is best to simulate, so that everyone can help you better answer.
Your supplement is the same as the previous effect!
How PHP turns a one-dimensional array into a two-dimensional array
$re =array (); for ($i =0; $i<>
http://www.bkjia.com/PHPjc/903476.html www.bkjia.com true http://www.bkjia.com/PHPjc/903476.html techarticle thinkphp A two-dimensional array into a label applicable one-dimensional array method Summary, thinkphp dimension This article summarizes thinkphp the one-dimensional array method that the two-dimensional array becomes the label. Share to the big ...