logic - How to add key to label when label has value exactly same to key ? ....PHP -
user gives input label , key other parameters(key , label example) want add key label once means @ first execution (first button press - after on every button click should not add; php file loads on every button)after should avoided add (prepend) (key_valuelabel_value) existing code adds key label fails when if user gives label has value similar key.
for example:- key='123' , label='123 test' condition fails
.
so suggest me on how can handle case ?
this php, everytime reloads counter failed.
i don't asking why need that. hope code can helps:
function iskeyinlabel($key, $label) { $keys = explode(' ', $label); // remove last element (it's label) array_pop($keys); return in_array($key, $keys); }
usage example:
// condition returns true if (iskeyinlabel('456', '123 456 789 test')) { // exists }
notice: of course can't use keys or labels spaces
upd: you'll need variable, example:
// of course need place can save array // possible place can use session or cookies, or // whatever want, here session usage example session_start(); // hash have keys executed $execkeys = isset($_session['execkeys'])?$_session['execkeys']:array(); // assuming $execkeys[$label] array if (isset($execkeys[$label]) && in_array($key, $execkeys[$label])) { // code executed } else { $execkeys[$label] = isset($execkeys[$label])?$execkeys[$label]:array(); $execkeys[$label][] = $key; // , if still need $label = $key.' '.$label; } $_session['execkeys'] = $execkeys;
Comments
Post a Comment