Husna Humaira Husna Humaira - 1 year ago 44
PHP Question

Display random button in PHP

I'm doing a simple php calculator. And now I want to try shuffle the calculator button yet the button still hold the same value.
This is what I've now


<form id="calculator">
<input type="text"id="txtDisplay" value="0" disabled />

<input type="button" id="btnDelete" value="CLR"/><input type="button" id="btnBackspace" value="BKS"/><input type="button" id="btnDivide" value="/" /><input type="button" id="btnMultiply" value="*" />

<input type="button" id="btnSeven" value="7" /><input type="button" id="btnEight" value="8" /><input type="button" id="btnNine" value="9" /><input type="button" id="btnSubtract" value="-" />

<input type="button" id="btnFour" value="4" /><input type="button" id="btnFive" value="5" /><input type="button" id="btnSix" value="6" /><input type="button" id="btnAdd" value="+" />

<input type="button" id="btnOne" value="1" /><input type="button" id="btnTwo" value="2" /><input type="button" id="btnThree" value="3" /><input type="button" id="btnEquals" value="=" />

<input type="button" id="btnZero" value="0" /><input type="button" id="btnDecimal" value="." />
<div class="clear"></div>

I'm newbie in PHP, so I really-2 need your help. Thanks a lot in advance to those who will help.


I think you expects like this.

echo '<form id="calculator"><input type="text" id="txtDisplay" value="0" disabled />&nbsp;&nbsp;<input type="button" onClick="history.go(0)" value="Refresh">&nbsp;&nbsp;';
$inputs['input']['id'] = array('btnDelete','btnBackspace','btnDivide','btnMultiply','btnSeven','btnEight','btnNine','btnSubtract','btnFour','btnFive','btnSix','btnAdd','btnOne','btnTwo','btnThree','btnEquals','btnZero','btnDecimal');
$inputs['input']['value'] = array('CLR','BKS','/','*','7','8','9','-','4','5','6','+','1','2','3','=','0','.');
$numbers = range(0, 17);
foreach ($numbers as $num)
  echo '<input type="button" id="'.$inputs['input']['id'][$num].'" value="'.$inputs['input']['value'][$num].'"/>';
echo '<div class="clear"></div></form>';