Jump to content



Photo

php coding help


  • Please log in to reply
No replies to this topic

#1 SlayerS_BoxeR

SlayerS_BoxeR

    Neowinian

  • Joined: 10-December 12
  • OS: Windows 7 Pro
  • Phone: Nexus 5

Posted 14 May 2013 - 14:02

suppose i have this code

$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;



if(!exists) {

$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;
}


else {
$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;

}

now i don't want those codes to copy paste repetitively, but instead I want to put a variable/value? so like





if (!exists)

{
$value

}


else {

$value

}


so I probably have to create a function in php then??


function list ()

{
$num = $_SESSION['count'];
$_SESSION['a'][$num] = $a_letter;
$_SESSION['b'][$num] = $b_letter;
$_SESSION['c'][$num] = $c_letter;
$_SESSION['d'][$num] = $d_letter;
$_SESSION['e'][$num] = $e_letter;
$_SESSION['f'][$num] = $f_letter;

}


so this becomes if(!exists) {$list} else {list} something like this?

how does this work please?