Data Structures

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Peskin

    Data Structures

    Is it possible to create data structures in PHP and if so, would someone
    provide a bried example?

    Example:

    I would like to create a Data Structure JRec which has the following fields

    lID (Long)
    dtDate (Date)
    sName (10 Character String)

    Thanks.

    Andrew
  • Sjoerd

    #2
    Re: Data Structures

    Use objects, classes or arrays. See the PHP manual for more details.

    Quick example:
    <?php
    $foo->lID = 10;
    $foo->dtDate = date();
    $foo->sName = "I like PHP";
    ?>

    Comment

    • Andrew Peskin

      #3
      Re: Data Structures

      Sjoerd wrote:[color=blue]
      > Use objects, classes or arrays. See the PHP manual for more details.
      >
      > Quick example:
      > <?php
      > $foo->lID = 10;
      > $foo->dtDate = date();
      > $foo->sName = "I like PHP";
      > ?>
      >[/color]
      Thank you very much for your quick response ... another question ... if
      you wanted to read/write data from/to a binary file, can you do this
      from PHP?

      Comment

      • Andrew Peskin

        #4
        Re: Data Structures

        Andrew Peskin wrote:[color=blue]
        > Sjoerd wrote:
        >[color=green]
        >> Use objects, classes or arrays. See the PHP manual for more details.
        >>
        >> Quick example:
        >> <?php
        >> $foo->lID = 10;
        >> $foo->dtDate = date();
        >> $foo->sName = "I like PHP";
        >> ?>
        >>[/color]
        > Thank you very much for your quick response ... another question ... if
        > you wanted to read/write data from/to a binary file, can you do this
        > from PHP?[/color]

        I should add ... can you read/write to a binary file, whole objects, in
        your example above, can you write $foo to a binary file, then read the
        binary file and place the record into a new variable $foo1?

        Comment

        • Ewoud Dronkert

          #5
          Re: Data Structures

          Andrew Peskin wrote:[color=blue]
          > I should add ... can you read/write to a binary file, whole objects, in
          > your example above, can you write $foo to a binary file, then read the
          > binary file and place the record into a new variable $foo1?[/color]

          Yes. See http://php.net/serialize and fwrite/fread.
          Also see http://php.net/download-docs.php

          --
          E. Dronkert

          Comment

          Working...