File: variables.html

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (993 lines) | stat: -rw-r--r-- 19,035 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
<HTML
><HEAD
><TITLE
>Variables</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.41"><LINK
REL="HOME"
TITLE="PHP3 Manual"
HREF="manual.html"><LINK
REL="UP"
TITLE="Syntax and grammar"
HREF="lang-syntax.html"><LINK
REL="PREVIOUS"
TITLE="Types"
HREF="types.html"><LINK
REL="NEXT"
TITLE="Constants"
HREF="constants.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP3 Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="types.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Syntax and grammar</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="constants.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="VARIABLES"
>Variables</A
></H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="VARIABLES.SCOPE"
>Variable scope</A
></H2
><P
>     The scope of a variable is the context within which it is defined.
     For the most part all PHP variables only have a single scope.
     However, within user-defined functions a local function scope is
     introduced.  Any variable used inside a function is by default
     limited to the local function scope.  For example:
    
    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
> 
$a = 1; /* global scope */ 

Function Test () { 
    echo $a; /* reference to local scope variable */ 
} 

Test ();
     </PRE
><P
></P
></DIV
><P
>     This script will not produce any output because the echo statement
     refers to a local version of the $a variable, and it has not been
     assigned a value within this scope.  You may notice that this is a
     little bit different from the C language in that global variables
     in C are automatically available to functions unless specifically
     overridden by a local definition.  This can cause some problems in
     that people may inadvertently change a global variable.  In PHP
     global variables must be declared global inside a function if they
     are going to be used in that function.  An example:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$a = 1;
$b = 2;

Function Sum () {
    global $a, $b;

    $b = $a + $b;
} 

Sum ();
echo $b;
     </PRE
><P
></P
></DIV
><P
>     The above script will output &quot;3&quot;.  By declaring $a and
     $b global within the function, all references to either variable
     will refer to the global version.  There is no limit to the number
     of global variables that can be manipulated by a function.

    </P
><P
>     A second way to access variables from the global scope is to use
     the special PHP-defined $GLOBALS array.  The previous example can
     be rewritten as:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$a = 1;
$b = 2;

Function Sum () {
    $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
} 

Sum ();
echo $b;
     </PRE
><P
></P
></DIV
><P
>     The $GLOBALS array is an associative array with the name of the
     global variable being the key and the contents of that variable
     being the value of the array element.

    </P
><P
>     Another important feature of variable scoping is the
     <I
CLASS="EMPHASIS"
>static</I
> variable.  A static variable exists
     only in a local function scope, but it does not lose its value
     when program execution leaves this scope.  Consider the following
     example:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>Function Test () {
    $a = 0;
    echo $a;
    $a++;
}
     </PRE
><P
></P
></DIV
><P
>     This function is quite useless since every time it is called it
     sets $a to 0 and prints &quot;0&quot;.  The $a++ which increments
     the variable serves no purpose since as soon as the function exits
     the $a variable disappears.  To make a useful counting function
     which will not lose track of the current count, the $a variable is
     declared static:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>Function Test () {
    static $a = 0;
    echo $a;
    $a++;
}
     </PRE
><P
></P
></DIV
><P
>     Now, every time the Test() function is called it will print the
     value of $a and increment it.

    </P
><P
>     Static variables are also essential when functions are called
     recursively.  A recursive function is one which calls itself.
     Care must be taken when writing a recursive function because it is
     possible to make it recurse indefinitely.  You must make sure you
     have an adequate way of terminating the recursion.  The following
     simple function recursively counts to 10:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>Function Test () {
    static $count = 0;

    $count++;
    echo $count;
    if ($count &#60; 10) {
        Test ();
    }
    $count--;
}
     </PRE
><P
></P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="VARIABLES.VARIABLE"
>Variable variables</A
></H2
><P
>     Sometimes it is convenient to be able to have variable variable
     names.  That is, a variable name which can be set and used
     dynamically.  A normal variable is set with a statement such as:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$a = "hello";
     </PRE
><P
></P
></DIV
><P
>     A variable variable takes the value of a variable and treats that as the
     name of a variable.  In the above example, <I
CLASS="EMPHASIS"
>hello</I
>, can
     be used as the name of a variable by using two dollar signs. ie.

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$$a = "world";
     </PRE
><P
></P
></DIV
><P
>     At this point two variables have been defined and stored in the
     PHP symbol tree: $a with contents "hello" and $hello with contents
     "world".  Therefore, this statement:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>echo "$a ${$a}";
     </PRE
><P
></P
></DIV
><P
>     produces the exact same output as:

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>echo "$a $hello";
     </PRE
><P
></P
></DIV
><P
>     ie. they both produce: <I
CLASS="EMPHASIS"
>hello world</I
>.

    </P
><P
>     In order to use variable variables with arrays, you have to
     resolve an ambiguity problem.  That is, if you write $$a[1] then
     the parser needs to know if you meant to use $a[1] as a variable,
     or if you wanted $$a as the variable and then the [1] index from
     that variable.  The syntax for resolving this ambiguity is:
     ${$a[1]} for the first case and ${$a}[1] for the second.

   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="VARIABLES.EXTERNAL"
>Variables from outside PHP</A
></H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="VARIABLES.EXTERNAL.FORM"
>HTML Forms (GET and POST)</A
></H3
><P
>      When a form is submitted to a PHP script, any variables from that
      form will be automatically made available to the script by
      PHP. For instance, consider the following form:

     </P
><P
>      <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="EXAMPLE"
><P
><B
>Example 5-2. Simple form variable</B
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;form action="foo.php3" method="post"&#62;
    Name: &lt;input type="text" name="name"&#62;&lt;br&#62;
    &lt;input type="submit"&#62;
&lt;/form&#62;
       </PRE
></DIV
></TD
></TR
></TABLE
>

     </P
><P
>      When submitted, PHP will create the variable
      <TT
CLASS="COMPUTEROUTPUT"
>$name</TT
>, which will will contain
      whatever what entered into the <I
CLASS="EMPHASIS"
>Name:</I
> field
      on the form.

     </P
><P
>      PHP also understands arrays in the context of form variables, but
      only in one dimension. You may, for example, group related
      variables together, or use this feature to retrieve values from a
      multiple select input:

     </P
><P
>     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="EXAMPLE"
><P
><B
>Example 5-3. More complex form variables</B
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;form action="array.html" method="post"&#62;
    Name: &lt;input type="text" name="personal[name]"&#62;&lt;br&#62;
    Email: &lt;input type="text" name="personal[email]"&#62;&lt;br&#62;
    Beer: &lt;br&#62;
    &lt;select multiple name="beer[]"&#62;
        &lt;option value="warthog"&#62;Warthog
        &lt;option value="guinness"&#62;Guinness
        &lt;/select&#62;
    &lt;input type="submit"&#62;
&lt;/form&#62;
       </PRE
></DIV
></TD
></TR
></TABLE
>

      </P
><P
>       If PHP's track_vars feature is turned on, either by the <A
HREF="configuration.html#INI.TRACK-VARS"
>track_vars</A
> configuration setting
       or the <TT
CLASS="COMPUTEROUTPUT"
>&lt;?php_track_vars?&gt;</TT
>
       directive, then variables submitted via the POST or GET methods
       will also be found in the global associative arrays
       $HTTP_POST_VARS and $HTTP_GET_VARS as appropriate.

     </P
><DIV
CLASS="SECT4"
><H4
CLASS="SECT4"
><A
NAME="AEN1831"
>IMAGE SUBMIT variable names</A
></H4
><P
>       When submitting a form, it is possible to use an image instead
       of the standard submit button with a tag like:

      </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;input type=image src="image.gif" name="sub"&#62;
       </PRE
><P
></P
></DIV
><P
>       When the user clicks somewhere on the image, the accompanying
       form will be transmitted to the server with two additional
       variables, sub_x and sub_y. These contain the coordinates of
       the user click within the image.  The experienced may note that
       the actual variable names sent by the browser contains a period
       rather than an underscore, but PHP converts the period to an
       underscore automatically.

    </P
></DIV
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="VARIABLES.EXTERNAL.COOKIES"
>HTTP Cookies</A
></H3
><P
>      PHP transparently supports HTTP cookies as defined by <A
HREF="http://www.netscape.com/newsref/std/cookie_spec.html"
TARGET="_top"
>Netscape's Spec</A
>.  Cookies are a
      mechanism for storing data in the remote browser and thus
      tracking or identifying return users.  You can set cookies using
      the <A
HREF="function.setcookie.html"
><B
CLASS="FUNCTION"
>SetCookie()</B
></A
> function.  Cookies are part
      of the HTTP header, so the SetCookie function must be called
      before any output is sent to the browser.  This is the same
      restriction as for the <A
HREF="function.header.html"
><B
CLASS="FUNCTION"
>Header()</B
></A
> function.
      Any cookies sent to you from the client will automatically be
      turned into a PHP variable just like GET and POST method data.

     </P
><P
>      If you wish to assign multiple values to a single cookie, just
      add <I
CLASS="EMPHASIS"
>[]</I
> to the cookie name.  For example:

     </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>SetCookie ("MyCookie[]", "Testing", time()+3600);
      </PRE
><P
></P
></DIV
><P
>      Note that a cookie will replace a previous cookie by the same
      name in your browser unless the path or domain is different.  So,
      for a shopping cart application you may want to keep a counter
      and pass this along.  i.e.

     </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="EXAMPLE"
><P
><B
>Example 5-4. SetCookie Example</B
></P
><PRE
CLASS="PROGRAMLISTING"
>$Count++;
SetCookie ("Count", $Count, time()+3600);
SetCookie ("Cart[$Count]", $item, time()+3600);
      </PRE
></DIV
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="VARIABLES.EXTERNAL.ENVIRONMENT"
>Environment variables</A
></H3
><P
>      PHP automatically makes environment variables available as normal
      PHP variables.
     
     <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>echo $HOME;  /* Shows the HOME environment variable, if set. */
      </PRE
><P
></P
></DIV
>

     </P
><P
>      Since information coming in via GET, POST and Cookie mechanisms
      also automatically create PHP variables, it is sometimes best to
      explicitly read a variable from the environment in order to make
      sure that you are getting the right version.  The
      <A
HREF="function.getenv.html"
><B
CLASS="FUNCTION"
>getenv()</B
></A
> function can be used for this.  You
      can also set an environment variable with the
      <A
HREF="function.putenv.html"
><B
CLASS="FUNCTION"
>putenv()</B
></A
> function.

   </P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="VARIABLES.TYPE-JUGGLING"
>Type juggling</A
></H2
><P
>     PHP does not require (or support) explicit type definition in
     variable declaration; a variable's type is determined by the
     context in which that variable is used. That is to say, if you
     assign a string value to variable <TT
CLASS="PARAMETER"
><I
>var</I
></TT
>,
     <TT
CLASS="PARAMETER"
><I
>var</I
></TT
> becomes a string. If you then assign
     an integer value to <TT
CLASS="PARAMETER"
><I
>var</I
></TT
>, it becomes an
     integer.

    </P
><P
>     An example of PHP's automatic type conversion is the addition
     operator '+'. If any of the operands is a double, then all
     operands are evaluated as doubles, and the result will be a
     double. Otherwise, the operands will be interpreted as integers,
     and the result will also be an integer. Note that this does NOT
     change the types of the operands themselves; the only change is
     in how the operands are evaluated.

    <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$foo = "0";  // $foo is string (ASCII 48)
$foo++;      // $foo is the string "1" (ASCII 49)
$foo += 1;   // $foo is now an integer (2)
$foo = $foo + 1.3;  // $foo is now a double (3.3)
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
$foo = 5 + "10 Small Pigs";     // $foo is integer (15)
     </PRE
><P
></P
></DIV
>

    </P
><P
>     If the last two examples above seem odd, see <A
HREF="variables.html#LANG-SYNTAX.STRINGCONV"
>String conversion</A
>.  

    </P
><P
>     If you wish to force a variable to be evaluated as a certain
     type, see the section on <A
HREF="variables.html#LANG-SYNTAX.TYPECASTING"
>Type casting</A
>. If you
     wish to change the type of a variable, see
     <A
HREF="function.settype.html"
><B
CLASS="FUNCTION"
>settype()</B
></A
>.

    </P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN1873"
>Determining variable types</A
></H3
><P
>      Because PHP determines the types of variables and converts them
      (generally) as needed, it is not always obvious what type a given
      variable is at any one time.  PHP includes several functions
      which find out what type a variable is. They are
      <A
HREF="function.gettype.html"
><B
CLASS="FUNCTION"
>gettype()</B
></A
>, <A
HREF="function.is-long.html"
><B
CLASS="FUNCTION"
>is_long()</B
></A
>,
      <A
HREF="function.is-double.html"
><B
CLASS="FUNCTION"
>is_double()</B
></A
>, <A
HREF="function.is-string.html"
><B
CLASS="FUNCTION"
>is_string()</B
></A
>,
      <A
HREF="function.is-array.html"
><B
CLASS="FUNCTION"
>is_array()</B
></A
>, and
      <A
HREF="function.is-object.html"
><B
CLASS="FUNCTION"
>is_object()</B
></A
>.
     
    </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="LANG-SYNTAX.TYPECASTING"
>Type casting</A
></H3
><P
>      Type casting in PHP works much as it does in C: the name of the
      desired type is written in parentheses before the variable which
      is to be cast.

     <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$foo = 10;   // $foo is an integer
$bar = (double) $foo;   // $bar is a double
      </PRE
><P
></P
></DIV
>
    
     </P
><P
>      The casts allowed are:
      <P
></P
><UL
><LI
><P
>(int), (integer) - cast to integer
       </P
></LI
><LI
><P
>(real), (double), (float) - cast to double
       </P
></LI
><LI
><P
>(string) - cast to string
       </P
></LI
><LI
><P
>(array) - cast to array
       </P
></LI
><LI
><P
>(object) - cast to object
      </P
></LI
></UL
>

     </P
><P
>      Note that tabs and spaces are allowed inside the parentheses, so
      the following are functionally equivalent:

     <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$foo = (int) $bar;
$foo = ( int ) $bar;
      </PRE
><P
></P
></DIV
>

    </P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="LANG-SYNTAX.STRINGCONV"
>String conversion</A
></H3
><P
>      When a string is evaluated as a numeric value, the resulting
      value and type are determined as follows.

     </P
><P
>      The string will evaluate as a double if it contains any of the
      characters '.', 'e', or 'E'. Otherwise, it will evaluate as an
      integer.
     
     </P
><P
>      The value is given by the initial portion of the string. If the
      string starts with valid numeric data, this will be the value
      used. Otherwise, the value will be 0 (zero). Valid numeric data
      is an optional sign, followed by one or more digits (optionally
      containing a decimal point), followed by an optional
      exponent. The exponent is an 'e' or 'E' followed by one or more
      digits.

     <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>$foo = 1 + "10.5";      // $foo is double (11.5)
$foo = 1 + "-1.3e3";    // $foo is double (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is integer (1)
$foo = 1 + "bob3";      // $foo is integer (1)
$foo = 1 + "10 Small Pigs";     // $foo is integer (11)
$foo = 1 + "10 Little Piggies"; // $foo is integer (11); 
$foo = "10.0 pigs " + 1;        // $foo is int (11)
$foo = "10.0 pigs " + 1.0;      // $foo is double (11)     
      </PRE
><P
></P
></DIV
>

     </P
><P
>      The type of the variable depends on the second not on the first
      expression, when the first expression is a string.

     </P
><P
>      For more information on this conversion, see the Unix manual
      page for strtod(3).
  </P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="types.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="manual.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="constants.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Types</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="lang-syntax.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Constants</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>