nochlux Posted May 15, 2013 Share Posted May 15, 2013 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 come up with a function - 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; } $value = function list(); if (!exists) { $value } else { $value } How does this work please? Link to comment https://forums.phpfreaks.com/topic/278008-php-function-help/ Share on other sites More sharing options...
davidannis Posted May 15, 2013 Share Posted May 15, 2013 I can't follow what you are doing. Looks to me like you do the same thing in your if{} and your else{} Then you create a function that returns nothing. Sorry I can not help more. Link to comment https://forums.phpfreaks.com/topic/278008-php-function-help/#findComment-1430105 Share on other sites More sharing options...
requinix Posted May 15, 2013 Share Posted May 15, 2013 ...You're doing the exact same thing in not just three places but in both branches of an if. It's not a problem of code reuse but of code redundancy. Link to comment https://forums.phpfreaks.com/topic/278008-php-function-help/#findComment-1430107 Share on other sites More sharing options...
Q695 Posted May 15, 2013 Share Posted May 15, 2013 Do it on your frame layout, so it is on all pages by default. Link to comment https://forums.phpfreaks.com/topic/278008-php-function-help/#findComment-1430114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.