Jump to content

[SOLVED] Returning an array data


ainoy31

Recommended Posts

Hello-

 

I need a second eye on this code I have.  I am parsing an XML file and returning the data back as an array.  However, nothing returns back even though I can echo the data to the screen.  Here is the code:

 

predump(track_PITD($pro));

 

function track_PITD($pro)

{

$xmlurl = "http://xxx/xxx/xxx.asp?pronumber=$pro&All=yes";

$data = file_get_contents($xmlurl);

if($data)

{

$xmlparser = xml_parser_create();

$fp = fopen($xmlurl, 'r');

$xmldata = fread($fp, 4096);

xml_parse_into_struct($xmlparser,$xmldata,$values,$index);

xml_parser_free($xmlparser);

  foreach($values as $xmlarray)

  {

      if($xmlarray[tag] == 'PROSTATUS')

      {

            $pu_date = $xmlarray[attributes][PICKUPDATE];

            if($xmlarray[attributes][DATEDELIVERED] != '')

            {

                  $deliv_date = $xmlarray[attributes][DATEDELIVERED];

                  $status = 'Delivered';

                  $delivered = true;

              }

              else

            {

                  $deliv_date = null;

                  $delivered = false;

              }

        }

    }

    return array($delivered, false, $status, $deliv_date, $pu_date);

}

}

My predump array should have the $pu_date, $deliv_date, and the status but the returned array is empty.  Hope this clear enough.  Much appreciation.  Thank you.  AM

Link to comment
Share on other sites

I figured it out.  Solution:

 

Instead of if($xmlarray[attributes][DATEDELIVERED] != ''), I had to do if($xmlarray[attributes][DATEDELIVERED] != 'null), since I was not looking for an empty string but value.  As for the $pu_date, I had to check to see if it has been set using

if(!isset($pu_date))

{

$pu_date = $xmlarray[attributes][PICKUPDATE];

}

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.