I have the following Python code snippet and I am trying to convert this to PHP. This actually generates .  Python:  x,n=0,1&lt;&lt;int(sys.argv[1]) while n&gt;x:print bin(n+x^x/2)[3:];x+=1   PHP  &lt;?php  fscanf(STDIN, "%d\n", $number); $x=0; $n=1&lt;&lt;$number  while($n &gt; $x) {     print decbin($n+$x^$x/2);     x++; }   Now, in the Python code there is a code at 2nd line inside the while loop:   bin(n+x^x/2)[3:];   I have converted this line to:  decbin($n+$x^$x/2);   but, what should be this: [3:] in PHP? And am I right for as far as I converted?
50285
Is there a way to substring a string in Python, to get a new string from the third character to the end of the string?  Maybe like myString[2:end]?  If leaving the second part means 'till the end', and if you leave the first part, does it start from the start?
38011
I am developing a PHP application in which I am in need to store values bigger than 1 million, but with the flexibility of having floating points. I know the traditional float and double. I am looking to store only up to two decimal points, and will only handle operations with numbers that have 2 decimals exclusively.  I have chosen my column type of double and unsigned, but whenever I store a row with a value bigger than one million, it gets truncated to 999999.99  Why is this? I am looking for the right datatype/solution. If you could point me in the right direction, I will appreciate it a lot!  Thank you for your time in advance!  Cheers.
17001
I'm wondering where I find the source to show how the operator ** is implemented in Python.  Can someone point me in the right direction?
1921
PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array contains only numeric keys? Basically, I want to be able to differentiate between this: $sequentialArray = [     'apple', 'orange', 'tomato', 'carrot' ];  and this: $assocArray = [     'fruit1' =&gt; 'apple',     'fruit2' =&gt; 'orange',     'veg1' =&gt; 'tomato',     'veg2' =&gt; 'carrot' ];
23996
I am a newbie to Python and have come across the following example in my book that is not explained very well. Here is my print out from the interpreter:  &gt;&gt;&gt; s = 'spam' &gt;&gt;&gt; s[:-1] 'spa'   Why does slicing with no beginning bound and a '-1' return every element except the last one? Is calling s[0:-1] logically the same as calling s[:-1]? They both return the same result. But I'm not sure what python is doing exactly. Any help would be greatly appreciated.
101805
I am not familiar with PHP at all and had a quick question.  I have 2 variables pricePerUnit and InvoicedUnits. Here's the code that is setting these to values:  $InvoicedUnits = ((string) $InvoiceLineItem-&gt;InvoicedUnits); $pricePerUnit = ((string) $InvoiceLineItem-&gt;PricePerUnit);   If I output this, I get the correct values. Lets say 5000 invoiced units and 1.00 for price.  Now, I need to show the total amount spent. When I multiply these two together it doesn't work (as expected, these are strings).  But I have no clue how to parse/cast/convert variables in PHP.  What should I do?
12905
How do you get the  of two variables in Python?  For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):  str1 = raw_input("Enter string one:") str2 = raw_input("Enter string two:") if logical_xor(str1, str2):     print "ok" else:     print "bad"   The ^ operator seems to be bitwise, and not defined on all objects:  &gt;&gt;&gt; 1 ^ 1 0 &gt;&gt;&gt; 2 ^ 1 3 &gt;&gt;&gt; "abc" ^ "" Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: unsupported operand type(s) for ^: 'str' and 'str'
17043
I have a Python script which takes as input a list of integers, which I need to work with four integers at a time.  Unfortunately, I don't have control of the input, or I'd have it passed in as a list of four-element tuples.  Currently, I'm iterating over it this way: for i in range(0, len(ints), 4):     # dummy op for example code     foo += ints[i] * ints[i + 1] + ints[i + 2] * ints[i + 3]  It looks a lot like &quot;C-think&quot;, though, which makes me suspect there's a more pythonic way of dealing with this situation.  The list is discarded after iterating, so it needn't be preserved.  Perhaps something like this would be better? while ints:     foo += ints[0] * ints[1] + ints[2] * ints[3]     ints[0:4] = []  Still doesn't quite &quot;feel&quot; right, though.  :-/ Related question:
26280
What is an easy way in Python to format integers into strings representing thousands with K, and millions with M, and leaving just couple digits after comma?  I'd like to show 7436313 as 7.44M, and 2345 as 2,34K.  Is there some % string formatting operator available for that? Or that could be done only by actually dividing by 1000 in a loop and constructing result string step by step?
56680
I've seen both the blocks of code in use several different times, personally I have always used the first but my question is: is there a functional difference, and if there is what is it?  while (condition is true ) {     // do something }  do {     // do something } while ( condition is true);   I will be applying this to PHP but I assume this is fairly language agnostic.
78348
You can do this in Python, but is it possible in PHP?  &gt;&gt;&gt; def a(): print 1 ...  &gt;&gt;&gt; def a(): print 2 ...  &gt;&gt;&gt; a() 2   e.g.:  &lt;? function var_dump() {} ?&gt; Fatal error: Cannot redeclare var_dump() in /tmp/- on line 1
23166
I'd like to define a command that takes 1, 2 or 3 arguments, and where the 2nd gets the same value as the 1st if it is not defined. I tried  \newcommand\codefrom[3][#1][Matlab]{ ... }   but I get an error saying     ! Illegal parameter number in definition of \codefrom.   &lt;to be read again>   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1   l.57 \newcommand{\codefrom}[3][#1][   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Matlab]   Is there any way to accomplish what I want to do?
73742
What is the best way to handle large numeric inputs in C++ (for example 10^100)?   For algorithms I usually switch over to ruby and I sometimes use strings.  Any other good methods?
57381
I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).  # The string, which has an a-acute in it. ss = u'Capit\xe1n' ss8 = ss.encode('utf8') repr(ss), repr(ss8)      ("u'Capit\xe1n'", "'Capit\xc3\xa1n'")   print ss, ss8 print &gt;&gt; open('f1','w'), ss8  &gt;&gt;&gt; file('f1').read() 'Capit\xc3\xa1n\n'   So I type in Capit\xc3\xa1n into my favorite editor, in file f2.  Then:  &gt;&gt;&gt; open('f1').read() 'Capit\xc3\xa1n\n' &gt;&gt;&gt; open('f2').read() 'Capit\\xc3\\xa1n\n' &gt;&gt;&gt; open('f1').read().decode('utf8') u'Capit\xe1n\n' &gt;&gt;&gt; open('f2').read().decode('utf8') u'Capit\\xc3\\xa1n\n'   What am I not understanding here? Clearly there is some vital bit of magic (or good sense) that I'm missing. What does one type into text files to get proper conversions?  What I'm truly failing to grok here, is what the point of the UTF-8 representation is, if you can't actually get Python to recognize it, when it comes from outside. Maybe I should just JSON dump the string, and use that instead, since that has an asciiable representation! More to the point, is there an ASCII representation of this Unicode object that Python will recognize and decode, when coming in from a file?  If so, how do I get it?  &gt;&gt;&gt; print simplejson.dumps(ss) '"Capit\u00e1n"' &gt;&gt;&gt; print &gt;&gt; file('f3','w'), simplejson.dumps(ss) &gt;&gt;&gt; simplejson.load(open('f3')) u'Capit\xe1n'
32884
If I define an array in PHP such as (I don't define its size):  $cart = array();   Do I simply add elements to it using the following?  $cart[] = 13; $cart[] = "foo"; $cart[] = obj;   Don't arrays in PHP have an add method, for example, cart.add(13)?
60449
I see that within MySQL there are Cast() and Convert() functions to create integers from values, but is there any way to check to see if a value is an integer?  Something like is_int() in PHP is what I am looking for.
116782
Possible Duplicate:          see this code    #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))     int array[] = {23,34,12,17,204,99,16};     int main()     {         int d;         for(d=-1;d &lt;= TOTAL_ELEMENTS-2;d++)            printf("%d\n",array[d+1]);         return 0;    }    now this loop won't run. sizeof() would return an unsigned value so TOTAL_ELEMENTS has an unsigned value. now , coming to the for loop, please tell me if the unary operator '-' works on signed int 2 or an implicit conversion takes place into unsigned and then the '-' operator works.