How do I know that the column matches the name if I have an array? So I have a loop, the name of the column goes from 1 to 6. To remove the image on click I
This does not work. If I type $ i
to 1
at $ product_id = "product_gallery _" + [$ i];
($ i = 1; $ i & lt; = 6; $ i ++) {$ product_img = " Product_gallery _ "+ [$ i]; If ($ model-> getAttributeLabel ($ product_id) == $ image_attr) // is not sure about $ image_attr, it was passed from seeing it {$ filename = $ model-> $ Product_img; To unlink ($ path $ file name.); $ Model- & gt; Product_gallery _ [$ i] = "default.png"; $ Models & gt; Save (); Echo "removed"; }}
Uses php (dot) not in the form of concatenation operator + Sign. Apart from this, [] (square cell) is used to find the ARA elements with keys, so that different variables such as $ variable [$ key]
$ variable < To reach
$'s
element of ($ i = 1; $ i & lt; =) for / code> array
6; $ I ++) {$ product_img = "Products_gallery _". $ I; If ($ model-> getAttributeLabel ($ product_id) == $ image_attr) // is not sure about $ image_attr, it was passed from seeing it {$ filename = $ model-> $ Product_img; To unlink ($ path $ file name.); $ Model- & gt; $ Product_img = "default.png"; $ Models & gt; Save (); Echo "removed"; }}
Comments
Post a Comment