if (en) then (f1) and if (ar) then (f2)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egturnkey
Forum Commoner
Posts: 34
Joined: Sun Jul 26, 2009 7:35 pm

if (en) then (f1) and if (ar) then (f2)

Post by egturnkey »

Hello Friends,

I've an function which has an array in arabic
now i want when lang goes english is shows me it but in english as follow


if lang=en show function f1 and if lang=ar show function f2


below the code but indeed show error ( not in function but in closing if and if not ) can you please fix it !

Code: Select all

 
if($lang == "en")
 
/////////////// function //////////
function career_level($c, $id) {
$levels = array("xxxxxxxx", "xxxxxxxxx");
if($id >= '0')
{
$level = $levels[$id];
return $level;
}
else
{
$select = "<select class='qc_textbox'name=\"careerlevel\">\n\t";
while(list($k,$v) = each($levels))
{
if($c >= '0')
{
if($c == $k)
{
$select .= "<option value=\"$k\" selected>$v</option>\n\t";
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
$select .= "</select>\n\n";
return $select;
}
}
//////////////////////////////////////////
 
 
else if($lang == "ar")
 
 
////////////////// same function //////////
 
function career_level($c, $id) {
$levels = array("xxxxxxxx", "xxxxxxxxx");
if($id >= '0')
{
$level = $levels[$id];
return $level;
}
else
{
$select = "<select class='qc_textbox'name=\"careerlevel\">\n\t";
while(list($k,$v) = each($levels))
{
if($c >= '0')
{
if($c == $k)
{
$select .= "<option value=\"$k\" selected>$v</option>\n\t";
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
else
{
$select .= "<option value=\"$k\">$v</option>\n\t";
}
}
$select .= "</select>\n\n";
return $select;
}
}
 
 
 
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: if (en) then (f1) and if (ar) then (f2)

Post by Griven »

You need curly braces after your IF statements.

Code: Select all

if($lang == "en") {
  //The rest of your English code here
}  else if($lang == "ar") {
  //The rest of your Arabic code here
}
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: if (en) then (f1) and if (ar) then (f2)

Post by cpetercarter »

I think that your code won't work because you are trying to define the function career_level() twice.

Can you not write the function once, like this:

Code: Select all

 
function career_level($c, $id)  {
if ($lang == "en" )  {
     $array = ("x", "y");  //English array
}  else  {
     $array = ("a", "b");  //Arabic array
}
 
//rest of code, which is the same for both languages
 
}
 
Post Reply