can't quite suss this

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

    can't quite suss this

    howdy all

    I have a script thats throwing an error

    basically $offset is a number i.e. 10, 20, 30 etc. and I want to get
    the first digit of this number as it increases and add one to the
    result and compare it. so if its 30, i want to get the '3' and add 1
    to make it '4' and see if it matches a number. this is what i used but
    i get an error

    } elseif ($pages = intval($offset{ 0})++1) {

    any direction would be greatly appreciated

    thanks
  • Justin Koivisto

    #2
    Re: can't quite suss this

    none wrote:[color=blue]
    > howdy all
    >
    > I have a script thats throwing an error
    >
    > basically $offset is a number i.e. 10, 20, 30 etc. and I want to get
    > the first digit of this number as it increases and add one to the
    > result and compare it. so if its 30, i want to get the '3' and add 1
    > to make it '4' and see if it matches a number. this is what i used but
    > i get an error
    >
    > } elseif ($pages = intval($offset{ 0})++1) {
    >
    > any direction would be greatly appreciated
    >
    > thanks[/color]

    try:
    $pages = intval(substr($ offset,0,1)) + 1

    --
    Justin Koivisto - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Comment

    • Pedro Graca

      #3
      Re: can't quite suss this

      none wrote:[color=blue]
      > I have a script thats throwing an error
      >
      > basically $offset is a number i.e. 10, 20, 30 etc. and I want to get
      > the first digit of this number as it increases and add one to the
      > result and compare it. so if its 30, i want to get the '3' and add 1
      > to make it '4' and see if it matches a number. this is what i used but
      > i get an error
      >
      > } elseif ($pages = intval($offset{ 0})++1) {[/color]
      _______________ ___^^^____

      did you mean "=="?


      if ($pages == ((int)($offset/10))+1) /* do something */


      Even though PHP is (almost) a typeless I try not to mix strings and
      numbers whenever possible.


      --
      USENET would be a better place if everybody read: | to email me: use |
      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
      http://www.expita.com/nomime.html | no attachments. |

      Comment

      • Pjotr Wedersteers

        #4
        Re: can't quite suss this

        none wrote:[color=blue]
        > howdy all
        >
        > I have a script thats throwing an error
        >
        > basically $offset is a number i.e. 10, 20, 30 etc. and I want to get
        > the first digit of this number as it increases and add one to the
        > result and compare it. so if its 30, i want to get the '3' and add 1
        > to make it '4' and see if it matches a number. this is what i used but
        > i get an error
        >
        > } elseif ($pages = intval($offset{ 0})++1) {
        >
        > any direction would be greatly appreciated
        >
        > thanks[/color]

        Do I see a = where == was meant ? Tip I read somewhere to prevent these
        easy-to-miss mistakes at least when literal constants are in play:

        If you need to evaluate if ($a==10) php won't complain when you type ($a=10)
        (evaluates to True).
        But if you use if (10==$a) omitting the = will surely generate an error.
        Pjotr


        Comment

        Working...