How to avoid repetitive value from array?

I am stuck in one of the problem.I have a problem to avoid repetitive value in session.

I have an array $questions_for_test whose value on print comes to be :-

[php]Array
(
[1] => Array
(
[0] => 9
[1] => 10
[2] => 15
[3] => 18
[4] => 35
)

[2] => Array
    (
        [0] => 1
        [1] => 4
        [2] => 5
        [3] => 7
        [4] => 8
        [5] => 11
        [6] => 12
        [7] => 14
        [8] => 20
        [9] => 21
    )

[3] => Array
    (
        [0] => 2
        [1] => 13
        [2] => 16
        [3] => 17
        [4] => 23
        [5] => 25
        [6] => 26
        [7] => 28
        [8] => 32
        [9] => 34
    )

[4] => Array
    (
        [0] => 6
        [1] => 19
        [2] => 36
        [3] => 40
        [4] => 42
        [5] => 48
    )

[5] => Array
    (
        [0] => 24
        [1] => 43
    )

)

Given, there are 5 levels,whose questions are given like on level 5,there are two questions. And i have following function which can return the random questions from the array. I passed the difficulty level as well,depending on previous answer they have submitted.Firstly, i have start from default level 1.

function returnRandomQuestion($questions_for_test, $difficulty_level){
$used_questions = $this->session->userdata(‘used_questions’); //this contain the question_id which is being used.
if(!is_array($used_questions))
$used_questions = array();
do{
$question_id = array_rand($questions_for_test[$difficulty_level], 1); //this generates the random question from above array for me
$check= in_array($question_id, $used_questions); //this checks the question which is being generated is present in array or not.If yes,i want to again call the function,but dont know how.so i used do-while,but it lets my array calling indefinate times.
}while($check!=1);
$used_questions[] =$questions_for_test[$difficulty_level][$question_id] ;
$this->session->set_userdata(‘used_questions’,$used_questions);
return $questions_for_test[$difficulty_level][$question_id];
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service