我有一个这样的array名字:$items
array(2) {
[0]=> array(8) { ["item_regel"]=> int(0) ["item_id"]=> string(2) "82" ["item_naam"]=> string(21) "Bureauschermen staand" ["item_uitvoering"]=> string(12) "100 x 200 cm" ["item_afmeting"]=> NULL ["item_kleur"]=> string(11) "Transparant" ["item_aantal"]=> string(1) "2" ["item_opmerking"]=> string(18) "Ik wil mijn logo 2" }
[1]=> array(8) { ["item_regel"]=> int(1) ["item_id"]=> string(3) "226" ["item_naam"]=> string(33) "Instructieborden Dibond aluminium" ["item_uitvoering"]=> string(10) "50 x 50 cm" ["item_afmeting"]=> NULL ["item_kleur"]=> string(5) "Blauw" ["item_aantal"]=> string(1) "2" ["item_opmerking"]=> string(4) "test" }
}
我发现这段代码可以预填重力表单列表字段:
add_filter( 'gform_field_value_list_one', 'itsg_prefill_list_one' );
function itsg_prefill_list_one( $value ) {
$list_array = array(
//List row
array(
"Product" => "Product",
"Afmeting" => "Good",
"Uitvoering" => "Product",
"Kleur" => "Product",
"Aantal" => "Product",
"Opmerking" => "Product",
),
//List row
array(
"Product" => "Product",
"Afmeting" => "Good",
"Uitvoering" => "Product",
"Kleur" => "Product",
"Aantal" => "Product",
"Opmerking" => "Product",
),
);
return $list_array;
}
现在这function充满了 fixed values。我想'List row' foreach在array上面做一行。
我试过这个但它不起作用:
add_filter( 'gform_field_value_list_one', 'itsg_prefill_list_one' );
function itsg_prefill_list_one( $value ) {
$items = $_SESSION["wishlist"];
$list_array = array(
foreach ($items as $keys => $values) {
array(
"Product" => $values["item_naam"],
"Afmeting" => $values["item_afmeting"],
"Uitvoering" => $values["item_uitvoering"],
"Kleur" => $values["item_kleur"],
"Aantal" => $values["item_aantal"],
"Opmerking" => $values["item_opmerking"],
),
}
);
return $list_array;
胡子哥哥