1

Here are my two arrays.

enter image description here

This array is $assesment I have tried the code given below and got $cat_array.

    foreach($assesment as $k => $v){
    $k2 = explode("_",$k);
    /* echo "cat : ".$cat = $k2[0] ."-". $v;
    echo "<br>";
    echo "Que : ".$que = $k2[1]."-". $v;
    echo "<br>"; */
    $cat_array[] = $k2[0]."-".$v;   
    }
print_r($cat_array);

enter image description here

1
  • can you post array in php format not in image format? Commented Feb 15, 2016 at 7:16

1 Answer 1

5

Just update your loop like as

$cat_array = array();
foreach($assesment as $k => $v){
    $k2 = explode("_",$k);
    if(isset($cat_array[$k2[0]])){
        $cat_array[$k2[0]] += $v;
    }else{
        $cat_array[$k2[0]] = $v;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.