Results 1 to 9 of 9

Thread: Implode??

  1. #1
    Join Date
    Feb 2003
    Location
    Albany, New York
    Posts
    2,988

    Implode??

    $number is an array. Lets say in the array, there is a 1, a 2, and a 3. I want to change $number array to just an int so the new value of number would be 123. I tried this:

    PHP Code:
    $number implode (""$number); 
    Will this work?

    Thanks.

  2. #2
    Join Date
    Mar 2003
    Posts
    878
    PHP Code:
    foreach($number as $each)
      
    $gluedNumber.=$each
    will this work??

  3. #3
    Join Date
    Jun 2004
    Location
    Digital Texas
    Posts
    55
    carp: yes thats how you would do it.

    to sil: yes, but only as long as you set $gluedNumber to "", otherwise it might create a error because ur trying to concatenate a string with something that doesnt exist.

  4. #4
    Join Date
    Mar 2003
    Posts
    878
    Originally posted by Nyture
    to sil: yes, but only as long as you set $gluedNumber to "", otherwise it might create a error because ur trying to concatenate a string with something that doesnt exist.
    u mean $gluedNumber has to be initialized to "" before the foreach loop??

    Thank you for pointing out my mistake

  5. #5
    Join Date
    Jan 2003
    Posts
    1,715
    PHP will magically create it as an empty string but, if you have all warnings turned on (like you should during development), it will point out the issue. It isn't nearly the problem it was when user-input was assigned to global variables, but it's still poor form.
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

  6. #6
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    This is what you should use :

    PHP Code:
    <?php

       $test 
    = array(1,2,3);
       echo 
    intval(implode("",$test));
    ?>
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  7. #7
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,082
    The documentation seems to be unclear...fyrestrtr, do you know if there's any functional difference between intval() and an explicit cast?

    God I hate how PHP pollutes the namespace with duplicate & otherwise useless functionality...it's bad enough there's no namespaces and no objects in the built in library...

    Here's to hoping it does something more elaborate than
    PHP Code:
    function intval($val 0)
    {
       return (int)(
    $val);


  8. #8
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Not as far as I know. The only different is that with intval(), you can specify the base that you want to have it converted to.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  9. #9
    Join Date
    May 2005
    Location
    Planet Earth
    Posts
    813
    He only asked if his php line was good.

    Which is working just fine
    PutFile.io Disrupting traditional file hosting.
    █ Signup Early and enjoy Unlimited space/bandwidth for your files hosting, Forever!
    █ No Ads.
    █ No Countdowns.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •