Results 1 to 5 of 5

Thread: What are Constants in PHP?

  1. #1
    Join Date
    Jul 2006
    Posts
    339

    What are Constants in PHP?

    Hi friends,
    I am new programmer for the PHP programming language. So I am not having enough knowledge about it. So thought that you guys would help me again. The solutions that you provide are very helpful. I am not able to get about the constants that are used in PHP. So please tell me what are the constants that are used in PHP?

  2. #2
    Join Date
    Jul 2006
    Posts
    289

    Re: What are Constants in PHP?

    The PHP constant is very similar to a PHP variable in that it is used to store a value. The constant() function returns the value of a constant. The syntax is as follows :
    PHP Code:
    constant(constant
    If you want to run a program several times using a different value each time, you do not need to search throughout the entire program and change the value at each instance.
    Signatures reduce available bandwidth

  3. #3
    Join Date
    Aug 2006
    Posts
    235

    Re: What are Constants in PHP?

    The constant parameter is used for specifying the name of the constant to check. The following example may help you :
    PHP Code:
    <?php
    define
    ("Wish","Hi! How are you today?");

    echo 
    constant("Wish");
    ?>
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: What are Constants in PHP?

    You can also make use of the valid and invalid constant names, just like I have used in following example :
    PHP Code:
    <?php

    define
    ("Demo",     "something");
    define("Demo1",    "something else");
    define("Demo2""something more");

    define("Demo3",    "something");

    define("Demo4""something"); 

    ?>

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: What are Constants in PHP?

    You can also retrieve the value of a constant dynamically. The following example demonstrates the same :
    PHP Code:
    <?php

    define
    ('Demo','It works!');
    define('Demo1','It works again!');

    $changing_variable 'bar';
    echo 
    constant('Demo2' strtoupper($changing_variable));

    $changing_variable 'Demo3';
    echo 
    constant('Demo3' strtoupper($changing_variable));

    ?>

Similar Threads

  1. How to parse constants in formula to cells in Excel
    By Hache hi in forum MS Office Support
    Replies: 14
    Last Post: 24-02-2012, 02:19 PM
  2. Where to put global constants in a C++ program?
    By Migueel in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 10:03 PM
  3. Replies: 4
    Last Post: 28-02-2010, 02:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,207,031.60651 seconds with 16 queries