A Problem in understanding PHP code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bsedigh_79@yahoo.com

    A Problem in understanding PHP code

    hi everybody.

    I'am a C# programmer and for one of my applications i searched web for
    a piece of code and finally i found it but in PHP.
    it was easy to understand the logic but i still have a problem with it.
    There is single line of code that i can't understand.Woul d u please
    help me and explain what is going on?

    Code :
    1)
    for ($i = 0; $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 &&
    $leap); $i++)
    $g_day_no -= $g_days_in_mont h[$i] + ($i == 1 && $leap);

    $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 && $leap) :-/

    2)
    what is div statement?
    There is a line of code like this:

    $gy += 4*div($g_day_no , 1461);

    what is div for?
    i searched in PHP functions but i did not find anything.

    Thanks for ur appreciates.
    Behzad

  • Yttrium

    #2
    Re: A Problem in understanding PHP code


    <Bsedigh_79@yah oo.com> a écrit dans le message de news:
    1118830313.5683 03.260120@g43g2 00...legr oups.com...
    [color=blue]
    > what is div statement?
    > There is a line of code like this:
    >
    > $gy += 4*div($g_day_no , 1461);
    >
    > what is div for?
    > i searched in PHP functions but i did not find anything.[/color]


    Hi,
    Div is Probably a user function...
    Because in Php, there's nothing like this..

    Bye,


    Comment

    • Carramba

      #3
      Re: A Problem in understanding PHP code

      On Wed, 15 Jun 2005 12:11:53 +0200, <Bsedigh_79@yah oo.com> wrote:
      [color=blue]
      > hi everybody.
      >
      > I'am a C# programmer and for one of my applications i searched web for
      > a piece of code and finally i found it but in PHP.
      > it was easy to understand the logic but i still have a problem with it.
      > There is single line of code that i can't understand.Woul d u please
      > help me and explain what is going on?
      >
      > Code :
      > 1)
      > for ($i = 0; $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 &&
      > $leap); $i++)[/color]

      its simple for loop...
      for //starting loop
      ($i = 0; //initiating count variable
      ($g_day_no) >= ( $g_days_in_mont h[$i] + ($i == 1 &&> $leap)); //just
      condition I addet () so maybe you se better
      can be more explained firts variable in condition $g_day_no
      if $g_day_no bigger or equal to ( $g_days_in_mont h[$i] + ($i == 1 &&>
      $leap))

      second variable in condition ( $g_days_in_mont h[$i] + ($i == 1 &&>
      $leap)), this one depends on i with will drow until the enequality returns
      true
      $i++) //grow by 1
      I'am guesing you forgot brakets? {}
      n that case the above code ll by executet while enequality is false
      [color=blue]
      > $g_day_no -= $g_days_in_mont h[$i] + ($i == 1 && $leap);
      >
      > $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 && $leap) :-/[/color]


      [color=blue]
      > 2)
      > what is div statement?
      > There is a line of code like this:
      >
      > $gy += 4*div($g_day_no , 1461);
      >
      > what is div for?[/color]

      I think that is some local funktion, you should check for that

      [color=blue]
      > i searched in PHP functions but i did not find anything.
      > Thanks for ur appreciates.
      > Behzad
      >[/color]



      --

      Thanx in advance
      _______________ _________
      BTW. I know my english is not best in the word, so please stop bugging me
      about my spelling. And yes Iam sorry you don't understand what I mean, but
      there is no point to yell at me. Have a nice day.

      Comment

      • Daniel Tryba

        #4
        Re: A Problem in understanding PHP code

        Bsedigh_79@yaho o.com wrote:[color=blue]
        > $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 && $leap) :-/[/color]

        Some implicit casting in action:
        i+true ==i+1
        i+false==i

        Comment

        • Jerry Stuckle

          #5
          Re: A Problem in understanding PHP code

          Bsedigh_79@yaho o.com wrote:[color=blue]
          > hi everybody.
          >
          > I'am a C# programmer and for one of my applications i searched web for
          > a piece of code and finally i found it but in PHP.
          > it was easy to understand the logic but i still have a problem with it.
          > There is single line of code that i can't understand.Woul d u please
          > help me and explain what is going on?
          >
          > Code :
          > 1)
          > for ($i = 0; $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 &&
          > $leap); $i++)
          > $g_day_no -= $g_days_in_mont h[$i] + ($i == 1 && $leap);
          >
          > $g_day_no >= $g_days_in_mont h[$i] + ($i == 1 && $leap) :-/
          >
          > 2)
          > what is div statement?
          > There is a line of code like this:
          >
          > $gy += 4*div($g_day_no , 1461);
          >
          > what is div for?
          > i searched in PHP functions but i did not find anything.
          >
          > Thanks for ur appreciates.
          > Behzad
          >[/color]

          Behzad,

          The code probably isn't commented as well as it could. However, my bust
          guess:

          1). $i is probably the month number (0-11 instead of 1-12). $leap would
          be true or false, depending on if it's a leap year. If it is a leap
          year ($leap == true) and February ($i == 1), then add 1 to the number of
          days in the month ($g_days_in_mon th[$i]). It works because a "true"
          value is converted to an int with the value of "1". False converted to
          an int has the value "0".

          2). I haven't seen it - I suspect's a user-defined function. I have no
          idea what it does, other than there are 1461 days every 4 years (with 3
          exceptions every 400 years...). So perhaps it returns an integer value
          of the results of the division. This would tell how many 4-year blocks
          there are, Multiply by 4 to get the number of years.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Geoff Berrow

            #6
            Re: A Problem in understanding PHP code

            I noticed that Message-ID: <vdmdncO0zrpNlS 3fRVn-uA@comcast.com> from
            Jerry Stuckle contained the following:
            [color=blue]
            >
            >2). I haven't seen it - I suspect's a user-defined function. I have no
            >idea what it does, other than there are 1461 days every 4 years (with 3
            >exceptions every 400 years...). So perhaps it returns an integer value
            >of the results of the division. This would tell how many 4-year blocks
            >there are, Multiply by 4 to get the number of years.[/color]

            Am I alone in thinking that this is possibly trying to reinvent existing
            PHP date manipulation functions?

            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • Jerry Stuckle

              #7
              Re: A Problem in understanding PHP code

              Geoff Berrow wrote:[color=blue]
              > I noticed that Message-ID: <vdmdncO0zrpNlS 3fRVn-uA@comcast.com> from
              > Jerry Stuckle contained the following:
              >
              >[color=green]
              >>2). I haven't seen it - I suspect's a user-defined function. I have no
              >>idea what it does, other than there are 1461 days every 4 years (with 3
              >>exceptions every 400 years...). So perhaps it returns an integer value
              >>of the results of the division. This would tell how many 4-year blocks
              >>there are, Multiply by 4 to get the number of years.[/color]
              >
              >
              > Am I alone in thinking that this is possibly trying to reinvent existing
              > PHP date manipulation functions?
              >[/color]

              Hi, Geoff,

              No, you're not alone :-)

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Bsedigh_79@yahoo.com

                #8
                Re: A Problem in understanding PHP code

                hi everybody

                thanks for your repleis.
                To see compelet code follow the this problem:



                Comment

                Working...