Tutorial - PHP Data Types

PHP has seven data types. The seven types are:

  • string,

  • integer,

  • float,

  • boolean,

  • array,

  • object, and

  • resource.


String


Strings hold characters such as "a," "abc," "www.java2s.com," etc. PHP strings are case-sensitive.

Object


Objects are complex variables that have multiple values, and they can have their own functions.

Resource


Resources might be picture data, or the result of an SQL query. We should free up resources after using them.





PHP References


Reference type variables are actually pointer to the real data. Once two variables are pointing to the same data, you can change either variable and the other one will also update.

When you use the = (assignment) operator, PHP takes the value from operand two and copies it into operand one.





Syntax


To assign by reference, you need to use the reference operator (&) after the equals operator (=), giving =&.





Example




<?PHP/*from w w w . j av a2 s . com*/
$a = 10;
$b =& $a;
print $a;
print $b;

++$a;
print $a;
print "n";
print $b;
print "n";
++$b;
print $a;
print "n";
print $b;
print "n";
?>


The code above generates the following result.


Note


As of PHP 5, objects are passed and assigned by reference by default. Assigning an object variable is actually copying its object handle, which means the copy will reference the same object as the original.

References allow a function to work directly on a variable rather than on a copy

11/Post a Comment/Comments

  1. When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

    ReplyDelete
  2. Paragraph writing can be another fun, in the event you be knowledgeable
    about then it is possible to write otherwise it is
    difficult to publish.

    ReplyDelete
  3. 596731 889431Its great as your other blog posts : D, thanks for posting . 342553

    ReplyDelete
  4. Great blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would
    really make my blog jump out. Please let me know where you got your theme.
    With thanks

    ReplyDelete
  5. Yes! Finaⅼly something about how to treat puffy еyes.

    ReplyDelete
  6. I hardly leave a reѕpօnse, hоwever after reading a ton of commentѕ on Tutоrial - PHᏢ Data Ƭypes.

    I do have a few questions fօr you if you don't mind.
    Is it onlү me or does it gіve the impresѕion like some of these remarks
    appear as if they are wгitten by brain dead individuals?
    :-P And, if yօu ɑre writing on other online
    sites, I would likе to follow you. Could уou post ɑ list of the complete urls of youг social cоmmunity siteѕ like your Facebook page, twitter feed, or linkedin profile?

    ReplyDelete
  7. This means the oven performing the thermal curing must be electric and not gas.

    ReplyDelete
  8. Every wеekend i usеd tо go to see tjis website, as i want
    enjoyment, ѕince thіs this ѕite conations actually
    fastidіous funny datra too.

    ReplyDelete
  9. Yes! Finally someone writes about what is the best laser hair removal machine for home.

    ReplyDelete
  10. I lⲟve it when folks get together and share opinions.
    Great blog, continue the good work!

    ReplyDelete
  11. Hey ӏ know this iѕ off topіc but I was wondering if
    you knew of any widgets I could add to my blog that automatically
    tweet my newest tᴡitter սpdates. I've been looking for a plug-in like this for qսite some time and wɑs hoping maybe you would have sоme
    exρerience with somethіng lіke this. Please let me know if you run into anytҺing.

    I truly enjoy reading your blog and I look forward to your new updates.

    ReplyDelete

Post a Comment

Previous Post Next Post

Sidebar Ads

Ads1
Ads2