|
Posted by kenoli on 09/28/55 11:57
Actually, some of it came up in some code you (Koncept-thanks) sent me
recently. Here are some examples:
preg_match('/^\d+$/',$v) && $q[] = "number = '{$v}'";
When the preg_match resolves to TRUE the array is set, when FALSE it
isn't. It is rather an elegantly and concise way of doing this. I
tried it out with the following alternatives:
TRUE && TRUE && $q[] = "number = '{$v}'";
TRUE && FALSE && $q[] = "number = '{$v}'";
As expected, the first sets the array and the second doesn't.
I tried using || in the following examples where you used && and got
the following results:
TRUE || FALSE && $q[] = "number = '{$v}'"; //doesn't set the array
FALSE || TRUE && $q[] = "number = '{$v}'"; //sets the array
What is the syntax here? I would think they should both set the array.
Can you link any number of functions that resolve to true or false with
operators like this? Which operators? What rules govern the construct?
What precedence??
Also, you used the format:
$q[] = "number = '{$v}'";
I think the more conventional is:
$q[] = "number => '{$v}'";
Also, I think:
$q = array("number => '{$v}'");
Is more conventional for initiatlizing an array. I have seen the
syntax you used for concatenating elements to an existing array (which
I guess actually takes place later in the code you sent as this is part
of a "switch."). I suppose your usage is the same as adding an element
to an array with no elements but this one hasn't been declared yet. I
know php is loose about declaring variables. At any rate, it works.
You had also used the "if endif" rather than "if {}" format that you
refer to above, which I am fiamiliar with from other languages and did
find documentation for at php.net.
Thus my question, which, as was pointed out by someone else, was not
very clear.
Your code brought my attention to the fact that I have now and then
seen syntax that is different from what I have learned from manuals or
that I have seen on php.net and I wondered if there is some place these
various alternatives are documented. At times, when I've asked about
specific things like the ternary operator (which confused me when I
first saw it in a book with explanation), I have been told I could
learn more looking at C documentation (I did finally find it burried
deep in php.net). I know that php is built on a kind of C language
core and I've wondered if it accepts other C syntax as a default.
Often it seems that you need to be familiar with these things in order
to find documentation for them. There is kind of an assumption of
basic knowledge, especially on pnp.net.
--Kenoli
Koncept wrote:
> In article <4lvv78F3qicuU1@individual.net>, J.O. Aho <user@example.net>
> wrote:
>
> > kenoli wrote:
> > > I often see syntax used in code snippets that is different than that
> > > indicated in the php manual, at least in the main topic pages.
> >
> > How do you mean differs?
> >
.. . . etc.
Navigation:
[Reply to this message]
|