Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有不同类的Php数组列表项_Php - Fatal编程技术网

具有不同类的Php数组列表项

具有不同类的Php数组列表项,php,Php,这是我的当前数组,在无序列表中显示列表项 function get_bottle_colors() { if(empty($_GET['cap_id'])) return false; $constructor_img = get_post_meta($_GET['cap_id'], 'product_constructor_image', true); if(is_array($constructor_img) && count($constructor

这是我的当前数组,在无序列表中显示列表项

function get_bottle_colors() {
    if(empty($_GET['cap_id'])) return false;
    $constructor_img = get_post_meta($_GET['cap_id'], 'product_constructor_image', true);
    if(is_array($constructor_img) && count($constructor_img)>0 && !empty($constructor_img[0]['title'])){
        $output = '<label>Bottle Color</label><ul>';
            foreach ($constructor_img as $key => $image) {
                if(empty($image['image'])) continue;
                $output .= '<li><a href="'.$image['image'].'" data-width="'.$img_size[0].'" data-height="'.$img_size[1].'"';
                $output .= '</a></li>';
            }
        $output .= '</ul>';
    }else{
        $output = '<label>Bottle Color</label><ul></ul>';
    }
    echo $output;
    die();
}
函数获取瓶子颜色(){
if(空($\u GET['cap\u id'])返回false;
$constructor\u img=get\u post\u meta($\u get['cap\u id','product\u constructor\u image',true);
如果(是数组($constructor\u img)&&count($constructor\u img)>0&&!空($constructor\u img[0]['title'])){
$output='瓶色
    '; foreach($constructor\u img as$key=>$image){ 如果(空($image['image'])继续;
    $output.='
  • 由于Anant找到了解决方案。必须像下面那样声明类数组

    function get_bottle_colors() {
        if(empty($_GET['cap_id'])) return false;
        $constructor_img = get_post_meta($_GET['cap_id'], 'product_constructor_image', true);
        if(is_array($constructor_img) && count($constructor_img)>0 && !empty($constructor_img[0]['title'])){
            $output = '<label>Bottle Color</label><ul>';
            $i = 0;
            $class_array = array("a","b","c","d","e","f","g","h","i","j","k","l","n","m","n","o","p");
                foreach ($constructor_img as $key => $image) {
                    if(empty($image['image'])) continue;
                    $category = 9;
                    $img_size = getimagesize($image['image']);
                    $output .= '<li class= "'.$class_array[$i].'"><a href="'.$image['image'].'" data-width="'.$img_size[0].'" 
    
                    data-height="'.$img_size[1].'"';
                    $output .= 'data-id="'.$_GET['cap_id'].'_'.$key.'" data-part="#constructor-bottles" class="sub-caps">'.$image['title'];
                    $output .= '</a></li>';     
                    $i++;
                }
                $output .= '</ul>';
            }else{
                $output = '
    
    <label>Bottle Color</label><ul></ul>';  }   echo $output;   die(); }
    
    函数获取瓶子颜色(){
    if(空($\u GET['cap\u id'])返回false;
    $constructor\u img=get\u post\u meta($\u get['cap\u id','product\u constructor\u image',true);
    如果(是数组($constructor\u img)&&count($constructor\u img)>0&&!空($constructor\u img[0]['title'])){
    $output='瓶色
      '; $i=0; $class_数组=数组(“a”、“b”、“c”、“d”、“e”、“f”、“g”、“h”、“i”、“j”、“k”、“l”、“n”、“m”、“n”、“o”、“p”); foreach($constructor\u img as$key=>$image){ 如果(空($image['image'])继续; $category=9; $img_size=getimagesize($image['image']); $output.='
    • ”; $i++; } $output.='
    '; }否则{ $output= 瓶子颜色
      ';}echo$output;die();}
      在循环之前设置一个数组,并使用递增计数器访问每一新行的值,或为包含该类名的每个产品设置一个新的元值。您希望我解释哪个选项?您希望类位于li或锚定上,并将所有类置于一个数组中,以及在基于cou迭代图像循环时输入类数组中的值并将其插入到你的li或主播tagGuo Cong中。请标记并向上投票给他人帮助。感谢人们对标记并向上投票给他人帮助的答案不感兴趣。也对告诉问题是否解决不感兴趣?浪费精力。删除我的答案。