dongzhiyan5693 2015-07-17 14:18
浏览 28
已采纳

你能做到这一点是PHP吗? 使用数组和if语句[关闭]

Just wondering how you can make this possible in PHP if you can or there is a better way it would be great.

With arrays and if statements

<?php
$products = array(
    0 => array(
        "product_name" => "Necklace",
        "product_price" => 10,
        "quantity" => 2,
        "handmade" => "true"
    ),
    array(
        "product_name" => "Bracelet",
        "product_price" => 17,
        "quantity" => 1,
        "handmade" => "false"
    ),
    array(
        "product_name" => "Handthingy",
        "product_price" => 6,
        "quantity" => 3,
        "handmade" => "true"
    )
);
<?php echo $product['handmade']; if('handmade'== true){
    //Do this
} else {
    //Do this
}
  • 写回答

1条回答 默认 最新

  • doufan6886 2015-07-17 14:22
    关注

    I think you are looking for the foreach loop:

    foreach($products as $product){
        if($product['handmade'] === 'true'){
           //do this
        }
        else {
           //do that
        }
    }
    

    This will iterate through the items in the product array, and check each one to see if it is handmade. If this is not what you are trying to do, give more information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案