0

This is my code:

 foreach ($category_attribute_list_value as $key => $value) {
        foreach ($value as $key2 => $value_fial) {
            if($key==0){
                $x[]=$value_fial->attribute_value;
                $x_id[]=$value_fial->attribute_value_id;
            }
        }}
        foreach ($category_attribute_list_value as $key_y => $value_y) {
        foreach ($value_y as $key2_y => $value_fial_y) {
            if($key_y!=0)
                {
                $y[]=$value_fial_y->attribute_value;
                $y_id[]=$value_fial_y->attribute_value_id;
                }
        }}

In an above code $x contain two value (L,XL) and same for $y, it's have two value (Blue, Green).

Now came to table data code

My table code is:

echo'<table cellpadding="0" cellspacing="0" border="1" class="pro_code_table">
<tr>
<td class="table_val_data">Code</td>';
foreach($x as $k_x => $v_x){
echo'<td class="table_val_data">'.$v_x.'</td>';
}
echo'</tr>';

foreach($y as $k_y_t=> $v_y_t){
echo'<tr><td class="table_val_data">'.$v_y_t.'</td>';
foreach($y as $k_y=> $v_y){
    foreach($x as $k_x => $v_x){
    $i=1;
    if($k_y_t==$k_y){
        echo'<td class="table_val_data">';
    //foreach($pro_code as $k_pro_code=> $v_pro_code){
    //if($k_x.'-'.$k_y==$k_pro_code){
        echo '<input type="text" name="edit_pro_code[]" value="'.$i.'"">';
    //}
    //}             
    echo'</td>';
    }    
    } 
    $i++;
}
echo'</tr>';
}
echo'</table>';

In an table code We split the data into X and y axises, X for an $x and y for an $y.

The whole table looped more the one time (assume it..!), in this cause only we have an error in looping

An first time looped data

The $y value is like this Array ( [0] => bule [1] => green ) Next time looping i want the same data, but i have the below o/p

Array ( [0] => bule [1] => green [2] => L [3] => XL [4] => bule [5] => green ) 

How its merged automatically., Ref the below screen shot enter image description here

6
  • The second time looping also i need same first loop o/p Commented Mar 30, 2016 at 5:13
  • The first time loop the value of $y is Array ( [0] => bule [1] => green ) Commented Mar 30, 2016 at 5:16
  • and then next time loop the same value of $y is like below Array ( [0] => bule [1] => green [2] => L [3] => XL [4] => bule [5] => green ) Commented Mar 30, 2016 at 5:17
  • the value is automatically merged, how can i unset the remains values Commented Mar 30, 2016 at 5:18
  • @Anant i got the solution Commented Mar 30, 2016 at 8:46

1 Answer 1

1

my answer is:

foreach ($category_attribute_list_value as $key => $value) {
    foreach ($value as $key2 => $value_fial) {
        if($key==0)
        {
            $x[]=$value_fial->attribute_value;
            $x_id[]=$value_fial->attribute_value_id;
        }
    }
}

foreach ($category_attribute_list_value as $key_y => $value_y) {
    foreach ($value_y as $key2_y => $value_fial_y) {
        if($key_y==1)
        {
            $y_temp[]=$value_fial_y->attribute_value;
            $y_id[]=$value_fial_y->attribute_value_id;
        }
    }
}
            $y=array_unique($y_temp);

                //$x=array('L','XL');
                //$y=array('P','dsfs'); 
                //$x_id=array(1,2);
                //$y_id=array(5,6);
                //$xv=array_combine($x_id, $x);
                //$yv=array_combine($y_id, $y);

echo'<table cellpadding="0" cellspacing="0" border="1" class="store_inven_table">
<tr>
<td class="table_val_data">Code</td>';
foreach($x as $k_x => $v_x){
echo'<td class="table_val_data">'.$v_x.'</td>';
}
echo'</tr>';

    foreach($y as $k_y_t=> $v_y_t){
    echo'<tr><td class="table_val_data">'.$v_y_t.'</td>';
    foreach($y as $k_y=> $v_y){
        foreach($x as $k_x => $v_x){
        if($k_y_t==$k_y){
            echo'<td class="store_val_data_input">';
            echo '<input type="text" name="store_pro_inv_qty[]" value="">
            <input type="text" value="'.$value_final_store->store_id.'" name="store_inventory_ids[]">';
        echo'</td>';
        }    
        } 
    }
    echo'</tr>';
    }

echo'</table>';
$x=array();$x_id=array();$y=array();$y_id=array();$value=array();

My o/p is like below: enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Mark this answer for others help. +10 from my side to do it yourself.
it shows like that "You can accept your own answer in 2 days"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.