Muhamad Yulianto
Muhamad Yulianto

Reputation: 1663

If else statement in codeigniter

i want to create if-else statement in codeigniter with my logic

If $language === "english" 

it will no change

$q["question_title"] = $q["question_title"]

else

it will change

$q["question_title"] = $q["question_title_**id**"]

the point is, i want to add "_id" in every php if $languege = no "english"

how to do that if php code inside of "[]" like $q["question_title"]

OR from query.php

    // translation language
    $site_lang = $this->session->userdata('site_lang');
    if ( $site_lang === 'english') {
    $question['questions'][$i]['question_title'] = $q->quiz_text;
    } else {
    $question['questions'][$i]['question_title'] = $q->quiz_text_id;
    }

so if i use code in /views and it read cookies in "english" it will get database "quiz_text" but if else it will get "quiz_text_id" from database but it not work in my query code.

Upvotes: 0

Views: 6177

Answers (1)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

First echo $site_lang what you getting then keep condition simple if title has already you don't need to set same value again so do a check like

$site_lang = $this->session->userdata('site_lang');
if ( $site_lang != 'english') {
  $question['questions'][$i]['question_title'] = $q->quiz_text_id;
}

Upvotes: 1

Related Questions