Results 1 to 2 of 2

Thread: messing around with array_sum

  1. #1
    Join Date
    Jun 2006
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking messing around with array_sum

    PHP Code:
    <?php
    $dollar 
    = array(1,2,30);
    $twoDollar = array(6,7,1);
    $total $dollar $twoDollar;
    echo 
    array_sum($twoDollar"\n" array_sum($dollar);
    echo 
    "total " $total;
    ?>
    i am messing around with this becasue i would like to see how i can use this to benifit me say ina cart or something. any thoughts on why i am geting this error.

    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'


    ANSWER
    for some reason php sees them and cancels out any array of the same after the first. so if you have simular arrays i.e. like above then you would only ge the top array.
    but if you want the sum of two arrays and they are the same use a command like this, and it should work just fine.
    PHP Code:
    <?php
    $dollar 
    = array(1,2,30);
    $twoDollar = array(6,7,1);
    echo 
    array_sumarray_merge($dollar$twoDollar) );
    ?>
    well i hope this helps someone.
    Last edited by pkcidstudio; 07-26-2006 at 07:52 PM.

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Your right PHP will drop the second array,but that is not what the error is about.Try reading about concatenation in the PHP manual.

Bookmarks

Posting Permissions

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