dongzou3751 2014-02-18 14:09
浏览 23
已采纳

如何查看列名是否与yii中的给定数组匹配

How do I find if the column name matches if I have an array? So I have a loop, the name of the column goes from 1 to 6 at the end. Looking to remove the image on click.

This doesn't work. It also doesn't work if I change $i to 1 in $product_id= "product_gallery_"+[$i];

 for ($i=1; $i<=6; $i++)
        {
        $product_img= "product_gallery_"+[$i];
            if($model->getAttributeLabel($product_id)==$image_attr) // not sure about $image_attr either, it was passed from view
            {   
            $filename = $model->$product_img;
            unlink($path.$filename);
            $model->product_gallery_[$i] = "default.png";
            $model->save();
            echo "removed";
            }
        }
  • 写回答

1条回答 默认 最新

  • dq1685513999 2014-02-18 14:13
    关注

    PHP uses the . (dot) as the concatenation operator not the + sign.

    Also the [] (square brackets) are used to address array elements by key not to access individual variables eg $variable[$key] to access the $key element of the $variable array

    for ($i=1; $i<=6; $i++)
    {
        $product_img= "product_gallery_".$i;
        if($model->getAttributeLabel($product_id)==$image_attr) // not sure about $image_attr either, it was passed from view
        {   
            $filename = $model->$product_img;
            unlink($path.$filename);
            $model->$product_img = "default.png";
            $model->save();
            echo "removed";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了