473,503 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Operators

I have an embarrassingly easy PHP question. I have the following line
of code:

$n *= $s = count($data[$i]);

Where $data is an array and $n and $s are scalars.

I'm familiar with the '*=' operator:

$n = $n * $s

But I'm not sure what the second '=' is doing.

Thanks,
R.D.

Aug 10 '06 #1
4 1175
it is really a confusing expression. i think $n will be set to
count($data[$]).

Ru*********@gmail.com wrote:
I have an embarrassingly easy PHP question. I have the following line
of code:

$n *= $s = count($data[$i]);

Where $data is an array and $n and $s are scalars.

I'm familiar with the '*=' operator:

$n = $n * $s

But I'm not sure what the second '=' is doing.

Thanks,
R.D.
Aug 10 '06 #2

Ru*********@gmail.com wrote:
I have an embarrassingly easy PHP question. I have the following line
of code:

$n *= $s = count($data[$i]);

Where $data is an array and $n and $s are scalars.

I'm familiar with the '*=' operator:

$n = $n * $s

But I'm not sure what the second '=' is doing.

Thanks,
R.D.
=, *=, += etc are evaluated from right to left so $s = count(...) is
calculated/assigned before $n = ...
http://www.php.net/manual/en/languag...ors.precedence

Its easier to understand if you split the line into two:

$s = count($data[$i]);
$n *= $s;

Aug 10 '06 #3
yo***********@gmail.com wrote:
it is really a confusing expression. i think $n will be set to
count($data[$]).

Ru*********@gmail.com wrote:
>>I have an embarrassingly easy PHP question. I have the following line
of code:

$n *= $s = count($data[$i]);

Where $data is an array and $n and $s are scalars.

I'm familiar with the '*=' operator:

$n = $n * $s

But I'm not sure what the second '=' is doing.

Thanks,
R.D.

No actually $n will be set to the product of $s*$n where $s is just the
total number of values in the array data[$i]. so if data[$i] contains
array(1, 2, 3, 5) the count will be 4. There for $s will now be 4 and
then $n*= $s is resolved.

Armando Padilla
Aug 10 '06 #4
On Wed, 09 Aug 2006 20:11:15 -0700, Russ.Dilley wrote:
I have an embarrassingly easy PHP question. I have the following line
of code:

$n *= $s = count($data[$i]);

Where $data is an array and $n and $s are scalars.

I'm familiar with the '*=' operator:

$n = $n * $s

But I'm not sure what the second '=' is doing.
Looks fine to me:
$ php -r '$data=array(1,2,3);$n=2; $n *= $s = count($data); print "N=$n\n";'
N=6
$
--
http://www.mgogala.com

Aug 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2484
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
4
2024
by: GianGuz | last post by:
Global new and delete operators can be overloaded to suite particulars needs. Typically they are overloaded to insert useful debugging/trace informations. What I would to discuss here concerns the...
6
1966
by: bearophileHUGS | last post by:
Sometimes I suggest to add things to the language (like adding some set methods to dicts), but I've seen that I tend to forget the meaning of six set/frozenset operators: s & t s &= t s | t s...
6
8966
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
2
3449
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
49
14856
by: raju | last post by:
hi can we compare two integers without using relational operators (== != < <= > >=) thanks rajesh s
0
1706
by: Syanide | last post by:
here's a bit info for you fellas: eg.. you have Square classes u wanna add public static int operator+ (Square s1, Square s2) { // your code here } comparision operators..
17
2420
by: Steve R. Hastings | last post by:
I have been studying Python recently, and I read a comment on one web page that said something like "the people using Python for heavy math really wish they could define their own operators". The...
28
5050
by: dspfun | last post by:
I'm trying to get a good understanding of how unary operators work and have some questions about the following test snippets. int *p; ~!&*++p--; It doesn't compile, why? The problem seems to be...
18
2620
by: Zach | last post by:
Can someone list the various macro operators and what they mean. Came across a function macro: #define max(a, b) ((a)>(b)?(a):(b)) What does "?" amd ":" mean in this statement? Zach
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.