duytin Posted April 19, 2007 Share Posted April 19, 2007 Dear All, I want to make a bitwise function but I don't know how to make it. Suggest that I want to make function my_bitwise($a,$b). I want the result as: Bits that are set in $a but not $b, and not vice versa. For example: $a=1010 ; $b=1100 I want result my_bitwise($a,$b)=0010. Pls hepl me! Thks in advance! Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted April 19, 2007 Share Posted April 19, 2007 http://www.php.net/manual/en/language.operators.bitwise.php edit: oh sorry, didn't really read your question all the way through Quote Link to comment Share on other sites More sharing options...
Barand Posted April 19, 2007 Share Posted April 19, 2007 <?php $a= 10 ; #1010 $b= 12 ; #1100 printf ('%04s', decbin($a & ~$b)); //--> 0010 ?> A and not B Quote Link to comment Share on other sites More sharing options...
duytin Posted April 19, 2007 Author Share Posted April 19, 2007 I want to say thanks very much to you! ;D <?php $a= 10 ; #1010 $b= 12 ; #1100 printf ('%04s', decbin($a & ~$b)); //--> 0010 ?> A and not B Quote Link to comment Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 How I can define a constant of an array? Foe example, I want to declaire: define ("A",array(1,2,3)); (The result I received is a error message ) Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted April 26, 2007 Share Posted April 26, 2007 You cant, now that was simple. you could serialize() an array in I guess... Quote Link to comment Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Dear Genericnumber1, Can you tell me more detail on serialize()... ??? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted April 26, 2007 Share Posted April 26, 2007 http://www.php.net/serialize but it's a pretty big pain just for a constant array Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 How I can define a constant of an array? Foe example, I want to declaire: define ("A",array(1,2,3)); (The result I received is a error message ) why would you want to do that? Quote Link to comment Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Hi boo_lolly, I'm trying to make a program this solve the Sudoku. In this programe, I use the array : array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)) many times in the program. So, I want to make a constant (not a variable!) represent this array. Quote Link to comment Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Hi boo_lolly, I'm trying to make a program this solve the Sudoku. In this programe, I use the array : array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)) many times in the program. So, I want to make a constant (not a variable!) represent this array. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 have you tried making this array a variable? $array = array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)); Quote Link to comment Share on other sites More sharing options...
duytin Posted April 27, 2007 Author Share Posted April 27, 2007 No problem when I use a variable, but it's not a variable naturally!!! Quote Link to comment Share on other sites More sharing options...
duytin Posted May 2, 2007 Author Share Posted May 2, 2007 Hi All, I want to get an array of data from the input of the user, for example: X11= 1, X12=5, ....,X99=6. I can make with an input apart but I don't know how to make with an array X[j]! Pls help me! :'( Quote Link to comment Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Pardon? Quote Link to comment Share on other sites More sharing options...
duytin Posted May 3, 2007 Author Share Posted May 3, 2007 For example, I want to write a PHP scrip which will: 1. Display an "0" 9X9 sudoku (default value 0 for all 81 squares). 2. The user will input some data in some squares, for example: square(1,1)=1, square(2,3)=5... 3. Transfer all 81 values of the Sudoku in an array, for example: for ($i=1;$i<=9;$i++) Quote Link to comment Share on other sites More sharing options...
duytin Posted May 3, 2007 Author Share Posted May 3, 2007 For example, I want to write a PHP scrip which will: 1. Display an "0" 9X9 sudoku (default value 0 for all 81 squares). 2. The user will input some data in some squares, for example: square(1,1)=1, square(2,3)=5... 3. Transfer all 81 values of the Sudoku in an array, for example: for ($i=1;$i<=9;$i++) { for ($j=1;$j<=9;$j++) { Sudoku[$i][$j]=square($i,$j); } } 4. After that, I will write a program to solve the Sudoku. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 3, 2007 Share Posted May 3, 2007 the form <form method='post'> <?php for ($r=0; $r<9; $r++) { for ($c=0; $c<9; $c++) { echo "<input type='text' name='sudoku[$r][$c]' size='3' value='' />"; } echo '<br>'; } echo "<input type='submit' name='action' value='Submit'>"; ?> </form> Process with $sudoku = $_POST['sudoku']; Quote Link to comment Share on other sites More sharing options...
duytin Posted May 5, 2007 Author Share Posted May 5, 2007 Thk u, teacher Barand! By the way, it seems that there's not remainder function in the PHP? ??? For example: remainder of 5/3 is 2. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted May 5, 2007 Share Posted May 5, 2007 there's a modulus operator... 5 % 3 is 2 Quote Link to comment Share on other sites More sharing options...
duytin Posted May 5, 2007 Author Share Posted May 5, 2007 Thks. I'm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.