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
https://forums.phpfreaks.com/topic/77638-solved-returning-an-array-data/
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];

}

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.