Barand Posted July 29, 2016 Share Posted July 29, 2016 http://php.net/manual/en/book.simplexml.php Yes, I saw the manual - no __set_state() in the list of methods SimpleXMLElement — The SimpleXMLElement class SimpleXMLElement::addAttribute — Adds an attribute to the SimpleXML element SimpleXMLElement::addChild — Adds a child element to the XML node SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element SimpleXMLElement::attributes — Identifies an element's attributes SimpleXMLElement::children — Finds children of given node SimpleXMLElement::__construct — Creates a new SimpleXMLElement object SimpleXMLElement::count — Counts the children of an element SimpleXMLElement::getDocNamespaces — Returns namespaces declared in document SimpleXMLElement::getName — Gets the name of the XML element SimpleXMLElement::getNamespaces — Returns namespaces used in document SimpleXMLElement::registerXPathNamespace — Creates a prefix/ns context for the next XPath query SimpleXMLElement::saveXML — Alias of SimpleXMLElement::asXML SimpleXMLElement::__toString — Returns the string content SimpleXMLElement::xpath — Runs XPath query on XML data If you re-arrange your array, so that the id to sort on is the key, then you could do the same user sort on that key. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2016 Share Posted July 29, 2016 (edited) If I remove the references to that method, this seems to work $data = array ( 0 => (array( 'DOCID' => '96651', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-102 ', )), 1 => (array( 'DOCID' => '96646', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCTITLE' => 'Order No. 3430 - Order Approving Modification One', 'DOCKETID' => 'CP2015-106 ', )), 2 => (array( 'DOCID' => '96645', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-114 ', )), 3 => (array( 'DOCID' => '96648', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-75 ', )), 4 => (array( 'DOCID' => '96649', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-76 ', )), 5 => (array( 'DOCID' => '96650', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-86 ', )), 6 => (array( 'DOCID' => '96652', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-93 ', )), 7 => (array( 'DOCID' => '96640', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-237 ', )), 8 => (array( 'DOCID' => '96641', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-238 ', )), 9 => (array( 'DOCID' => '96643', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-241 ', )), 10 => (array( 'DOCID' => '96653', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-242 ', )), 11 => (array( 'DOCID' => '96647', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-246 ', )), 12 => (array( 'DOCID' => '96644', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-3 ', )), 13 => (array( 'DOCID' => '96641', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'MC2016-164 ', )), 14 => (array( 'DOCID' => '96643', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'MC2016-167 ', )), ); usort($data, function($a,$b) { list($a1,$a2,$a3) = splitParts($a['DOCKETID']); list($b1,$b2,$b3) = splitParts($b['DOCKETID']); $x = strcmp($a1,$b1); if ($x == 0) { $y = $b2 - $a2; if ($y == 0) { return $b3 - $a3; } return $y; } return $x; }); function splitParts($s) { $k = strlen($s); $a = ['','','']; $i = 0; $p = 0; while ($i < $k) { $c = $s[$i++]; if (ctype_digit($c) && $p==0) $p = 1; if ($c=='-') { $c = $s[$i++]; ++$p; } $a[$p] .= $c; } return $a; } print_r ($data); giving Array ( [0] => Array ( [DOCID] => 96647 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-246 ) [1] => Array ( [DOCID] => 96653 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-242 ) [2] => Array ( [DOCID] => 96643 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-241 ) [3] => Array ( [DOCID] => 96641 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-238 ) [4] => Array ( [DOCID] => 96640 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-237 ) [5] => Array ( [DOCID] => 96644 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-3 ) [6] => Array ( [DOCID] => 96645 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-114 ) [7] => Array ( [DOCID] => 96646 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCTITLE] => Order No. 3430 - Order Approving Modification One [DOCKETID] => CP2015-106 ) [8] => Array ( [DOCID] => 96651 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-102 ) [9] => Array ( [DOCID] => 96652 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-93 ) [10] => Array ( [DOCID] => 96650 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-86 ) [11] => Array ( [DOCID] => 96649 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-76 ) [12] => Array ( [DOCID] => 96648 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-75 ) [13] => Array ( [DOCID] => 96643 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => MC2016-167 ) [14] => Array ( [DOCID] => 96641 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => MC2016-164 ) ) Edited July 29, 2016 by Barand Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted July 29, 2016 Author Share Posted July 29, 2016 My issue is with getting xml into an array now.. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2016 Share Posted July 29, 2016 long sigh... OK, post the XML. Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted July 29, 2016 Author Share Posted July 29, 2016 The file I posted earlier is all I have, the simple_xml is coming from someone else's compiled call to a database. Longer sigh... Quote Link to comment Share on other sites More sharing options...
Barand Posted July 29, 2016 Share Posted July 29, 2016 in the file you posted earlier (Fill_Id.txt) you have this line $xml = simplexml_load_string($ParseData); So it looks as though $parseData is the XML. Do you have anything similar for this new bit of data? Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 2, 2016 Author Share Posted August 2, 2016 Ok, first---- Thanks for all the help. Second, I have the following: I get the data into an array and then apply your function. I must need to sort or pass in one of the array columns. I do not get an error, but I also do not get the result. $table should contain the data from XML. I then put it into an Array and apply the function: foreach($table as $case) { $sortable[] = $case; } var_dump($sortable); 'I HAVE ATTACHED THE RESULTS TO THIS usort($sortable,function($a,$b) { list($a1, $a2, $a3) = splitParts($a); list($b1, $b2, $b3) = splitParts($b); $x = strcmp($a1, $b1); if ($x == 0) { $y = $b2 - $a2; if ($y == 0) { return $b3 - $a3; } return $y; } return $x; }); 'NOW I LOOP THROUGH $sortable to display results foreach($sortable as $case) { 'write out results to a table......... } DailyVarDump.txt Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2016 Share Posted August 2, 2016 OK, post the XML. Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 2, 2016 Author Share Posted August 2, 2016 I did, it was in the attached file. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2016 Share Posted August 2, 2016 That is NOT xml, it is a var dump output of some xml data that has been processed by simplexml. Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 2, 2016 Author Share Posted August 2, 2016 This is what the API they have is returning. It returns object from simplexml. That's all I can give you, below is the function that generates this: function GetDailyListingSummary($filterdate) { //ini_set('soap.wsdl_cache_enable', '0'); $x = new SoapClient(variable_get('prcwebservice'),variable_get('soapauth')); // make an API call and get data $result = $x->GetDailyListingSummary(array('docDate'=>$filterdate)); // Interpret the XML response $apiresult = simplexml_load_string($result->GetDailyListingSummaryResult->any); $dockets = $apiresult->DailyListingSummary->DailyListingData; return $dockets; } Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2016 Share Posted August 2, 2016 in the file you posted earlier (Fill_Id.txt) you have this line $xml = simplexml_load_string($ParseData); So it looks as though $parseData is the XML. Do you have anything similar for this new bit of data? Similarly, the code you just posted, the input to simplexml_load_string() is $result->GetDailyListingSummaryResult->any That should be the XML. Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 2, 2016 Author Share Posted August 2, 2016 I know this is a pain, but I did the following: $result->GetDailyListingSummaryResult->any and I did a var_dump($result) Here it is attached, just a long string.... VarDumpResult.txt Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 2, 2016 Author Share Posted August 2, 2016 If I just call the webservice that is supposed to generate the XML, attached is the XML RAW results, but not from the functions I presented. GetDailyListingSummary.xml Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 3, 2016 Author Share Posted August 3, 2016 Ok, here is where I stand, and I think I am over the initial roadblock. 1. I have the simplexml into an array. This is working. $sortable = array(); foreach ($table as $case) { $sortable[]=$case; } usort($sortable, function($a, b$) { //I DID THIS TO TEST. The sort was not seeing the $a, $b as a string //so I did the following $test1 = (string)$a->DOCKETID; // This got me just the element we want to sort on $test2 = (string)$b->DOCKETID; // This got me just the element we want to sort on list($a1, $a2, $a3) = splitParts($test1); // Calling the function you provided below list($b1, $b2, $b3) = splitParts($test2); $x = strcmp($a1, $b1); if ($x == 0) { $y = $b2 - $a2; if ($y == 0) { return $b3 - $a3; } return $y; } return $x; }); function splitParts($s) { $k = strlen($s); $a = ['','','']; $i = 0; $p = 0; while ($i < $k) { $c = $s[$i++]; if (ctype_digit($c) && $p==0) $p = 1; if ($c=='-') { $c = $s[$i++]; ++$p; } $a[$p] .= $c; } return $a; } NOW - The last piece of my confusion. The results we want this time are as below. The original sort is what we wanted in my initial request, and that worked great. The piece I'm stuck on now is to sort differently, as below. What we want: CP2015-75 CP2015-76 CP2015-86 CP2015-93 CP2015-102 CP2015-106 CP2015-114 CP2016-3 CP2016-237 CP2016-238 CP2016-241 CP2016-242 CP2016-246 MC2016-164 MC2016-167 What we are getting: CP2016-246 CP2016-242 CP2016-241 CP2016-238 CP2016-237 CP2016-3 CP2015-114 CP2015-106 CP2015-102 CP2015-93 CP2015-86 CP2015-76 CP2015-75 MC2016-167 MC2016-164 Quote Link to comment Share on other sites More sharing options...
lemaster777 Posted August 3, 2016 Author Share Posted August 3, 2016 Uhg.. Ok, learning more as I go. If I just switch the $y=$b2 - $a2; around to $y = $a2 - $b2; then it works. I can not thank you enough for helping me muddle through this. Not having access to the original authors source code for webservice api and other portions of this site, combined with my lack of php knowledge is making this a great adventure. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.