<?php


function saeed_captcha() {

    $par1 = mt_rand(2,8);
    $par1s = "";

    if(mt_rand(1,2) == 1){

        switch($par1){
            case 2: $par1s = "دو"; break;
            case 3: $par1s = "سه"; break;
            case 4: $par1s = "چهار"; break;
            case 5: $par1s = "پنج"; break;
            case 6: $par1s = "شش"; break;
            case 7: $par1s = "هفت"; break;
            case 8: $par1s = "هشت"; break;
        }

    }else{

        $par1s = $par1."";

    }


    
    $par2 = mt_rand(2,6);
    $par2s = "";
    switch($par2){
        case 2: $par2s = "دو"; break;
        case 3: $par2s = "سه"; break;
        case 4: $par2s = "چهار"; break;
        case 5: $par2s = "پنج"; break;
        case 6: $par2s = "شش"; break;
    }


    $op = "sum";
    $ops = "";
    switch(mt_rand(1,2)){
        case 1: $op = "sum"; break;
        case 2: $op = "mul"; break;
    }

    if($op == "sum"){

        switch(mt_rand(1,5)){
            case 1: $ops = "جمع با"; break;
            case 2: $ops = "+"; break;
            case 3: $ops = "بعلاوه"; break;
            case 4: $ops = "بعلاوه ی"; break;
            case 5: $ops = "بعلاوه‌ی"; break;
        }

    }else{

        switch(mt_rand(1,5)){
            case 1: $ops = "ضرب در"; break;
            case 2: $ops = "ضربدر"; break;
            case 3: $ops = "ضرب در عدد"; break;
            case 4: $ops = "×"; break;
            case 5: $ops = "ضرب‌در"; break;
        }

    }

    $question = "حاصل " . $par1s . " " . $ops . " " . $par2s;
    
    $answer = 0;
    if($op == "sum"){
        $answer = $par1 + $par2;
    }else{
        $answer = $par1 * $par2;
    }

    return array(
        'question' => $question,
        'answer' => $answer
    );


}