|
Posted by Toby A Inkster on 02/20/07 11:54
murrayatuptowngallery wrote:
> I think PHP is more flexible with variables...whether or not it is a
> good practice, they apparently do not need to be explicitly defined by
> type (they are interpreted by content?),
Mostly by *context* rather than *content*. For example:
<?php
// a single character string
$var = "4";
// Let's do regular-expression matching. $var is expected
// to be a string, so PHP treats it as a string.
$match_found = preg_match('/[0-9]/', $var);
// Let's do some maths. It doesn't make sense to do
// subtraction on strings, so PHP treats $var as a number.
$difference = $var - 1;
// $match_found is TRUE.
// $difference is 3.
?>
> but are they automatically assumed to be global?
What you're describing appears to be sessions, which are well supported by
PHP. Globals are something different -- they only exist within the scope
of an execution cycle (i.e., normally, a single page request).
I won't bother giving an example of how to use sessions, as Kimmo already
has.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|