Jump to content
  • 0
Sign in to follow this  
Followers 0

php coding help

Question

Posted

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?

Share this post


Link to post
Share on other sites

0 answers to this question

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.