Announcement

Collapse
No announcement yet.

Hope someone can help me with my PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hope someone can help me with my PHP

    Hello forum: I need help with the following PHP array within array shown in bold/italic below: $params = array(
    "requestID" => "xxxxxxxx",
    "account" => "xxxxxxxx",
    "originPoint" => array('countryCode' => 'US', 'postalCode' => $from_zip),
    "destinationPoint" => array('countryCode' => 'US', 'postalCode' => $to_zip),
    "payor" => 'T',
    "terms" => 'PPD',
    "stackable" => 'N',
    "baseCommodities" => array('commodity' => array('class' => 60, 'weight' => 1000) ),
    "accessorials" => array("accessorialCode" => $accArray)
    ); The array(commodity needs to contain from 1 to n entries for class & weight. I've had no luck getting a solution for this today, I've been pulling my hair out all day and I don't have much to spare. Hope someone can help. Thanks, Larry
    Larry
    Luce Kanun Web Design
    www.facebook.com/wajake41
    www.plus.google.com/116415026668025242914/posts?hl=en



    #2
    Re: Hope someone can help me with my PHP

    Maybe use the actual number 60 as your array key and it would have a value of 1000? Otherwise each iteration would overwrite the previous since they're all using the same array key of the literal 'class'.

    $class = 60;
    $weight = 1000;
    ...
    "baseCommodities" => array('commodity' => array($class => $weight) ),
    ...
    $class = 61;
    $weight = 2000;
    ...
    "baseCommodities" => array('commodity' => array($class => $weight) ),
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      Re: Hope someone can help me with my PHP

      Can you give us a little more background? What is this for? What's the relationship between commodity and class&weight? Would one commodity have more than 1 class&weight entry (that's what I'm inferring from your statement)? I would actually experiment with this format:

      "baseCommodities" => array('commodity' => array( array('class' => 60, 'weight' => 1000) ) ),

      I wrapped an additional array around your class and weight. This format allows you to include multiple class&weight values for the commodity element (eg. commodity = array( array('class'=>60,'weight'=>1000), array('class'=61,'weight'=>2000) );). The way you have it set up, you can't include more than one class&weight combo per commodity.

      Comment


        #4
        Re: Hope someone can help me with my PHP

        Hi David & Brandon: Thanks for your replies. After several hours I've come up with a solution that works. I have to use associative arrays. Brandon I think this is the same approach that you suggested. This is the associative array of arrays that works: $comArray = array (
        array('class' => '70', 'weight' => '660'),
        array('class' => '125', 'weight' => '460'),
        array('class' => '60', 'weight' => '960')
        );
        a
        nd this is how I'm using it in the message I'm creating: $params = array(
        "requestID" => "xxxxxxx",
        "account" => "xxxxxxxx",
        "originPoint" => array('countryCode' => 'US', 'postalCode' => $from_zip),
        "destinationPoint" => array('countryCode' => 'US', 'postalCode' => $to_zip),
        "payor" => 'T',
        "terms" => 'PPD',
        "stackable" => 'N',
        "baseCommodities" => array('commodity' => $comArray ),
        "accessorials" => array("accessorialCode" => $accArray)
        ); FYI. This is being used for the Estes Express LTL shipping quote API, so it needs to have multiple class & weight parameters for the items being shipped. Thanks again for your help, Larry
        Larry
        Luce Kanun Web Design
        www.facebook.com/wajake41
        www.plus.google.com/116415026668025242914/posts?hl=en


        Comment


          #5
          Re: Hope someone can help me with my PHP

          Yep, same thing I was talking about. Glad it worked.

          Comment


            #6
            Re: Hope someone can help me with my PHP

            Hi Brandon: But now I need to do it dynamically from 1 to n variables: $class[] & $weight[]. Any ideas about this? Larry
            Last edited by wajake41; 10-29-13, 09:05 AM.
            Larry
            Luce Kanun Web Design
            www.facebook.com/wajake41
            www.plus.google.com/116415026668025242914/posts?hl=en


            Comment


              #7
              Re: Hope someone can help me with my PHP

              You have separate class and weight arrays and you need to make [strike]combinations[/strike] pairs out of them? Are they indexed the same (meaning $class[0] needs to be paired with $weight[0])?

              I think the best option you have then is this:

              Code:
              $commArray = array();
              for ($i=0; $i<count($class); $i++) {
                  $commArray[] = array('class'=>$class[$i], 'weight'=>$weight[$i]);
              }
              Last edited by Brandon MUS; 10-29-13, 09:11 AM.

              Comment


                #8
                Re: Hope someone can help me with my PHP

                Thanks Brandon. Looks good to me, I'll give it a try. Larry
                Larry
                Luce Kanun Web Design
                www.facebook.com/wajake41
                www.plus.google.com/116415026668025242914/posts?hl=en


                Comment


                  #9
                  Re: Hope someone can help me with my PHP

                  Brandon: You get a gold star. That worked like a charm. MANY THANKS!! You've saved me a lot of time & grief. Larry
                  Larry
                  Luce Kanun Web Design
                  www.facebook.com/wajake41
                  www.plus.google.com/116415026668025242914/posts?hl=en


                  Comment

                  Working...
                  X