显示阵列循环

时间:2018-10-16 12:42:28

标签: php html

我想显示我的产品在php数组中。 有php数组

<?php
    $products = array(
        "product1" => array(
            "productName" => "Product 1",
            "productPrice" => "19.34",
            "productDescription" => "This is product 1",
            "productThumb" => "image-product-1.png",
        ),
        "product2" => array(
            "productName" => "Product 2",
            "productPrice" => "5.32",
            "productDescription" => "This is product 2",
            "productThumb" => "image-product-2.png",
        ),
    );
?>

我想在html代码中这样显示它,但没有描述

<div class="product">
    <div class="productThumb"><img src=""></div>
    <div class="productName"></div>
    <div class="productPrice"></div>
</div>

2 个答案:

答案 0 :(得分:1)

尝试以下代码

<?php

     $products = array(
        "product1" => array(
            "productName" => "Product 1",
            "productPrice" => "19.34",
            "productDescription" => "This is product 1",
            "productThumb" => "image-product-1.png",
        ),
        "product2" => array(
            "productName" => "Product 2",
            "productPrice" => "5.32",
            "productDescription" => "This is product 2",
            "productThumb" => "image-product-2.png",
        ),
    );

    foreach($products as $product_data)
    {
    ?>
        <div class="product">
        <div class="productThumb"></div><?php echo $product_data['productThumb']; ?> </div>
        <div class="productName"> <?php echo $product_data['productName']; ?> </div>
        <div class="productPrice"> <?php echo $product_data['productPrice']; ?></div>
        </div>

    <?php
    }
?>

答案 1 :(得分:0)

这很容易:-

override fun getLocations(): Single<Collection<Location>> =
        tokenUseCases.getToken()
                .flatMap { jwt ->
                    wrapApiRequestSingle({
                        mobileRemote.getLocations(jwt.accessToken)
                    }, jwt)
                }