每个数组行的数组 PHP

Array for each array row PHP

我有一个名为 $itemsarray,如下所示:

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被固定的values填满了。我想在上面的 array 中做一个 'List row' foreach 行。

我试过了,但行不通:

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;
}

在循环内将循环数组中的项目添加到数组中

add_filter( 'gform_field_value_list_one', 'itsg_prefill_list_one' );
function itsg_prefill_list_one( $value ) {

    foreach ($_SESSION["wishlist"] as $keys => $values) {
        $list_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;
}