public function convertToArray() { try { $allData = array(); $eachData = array(); $con = file_get_contents($this->file); $con = trim($con); $xml = new SimpleXMLElement($con); if ($xml->count() > 0) { foreach ($xml->children() as $element) { if ($element->count() > 0) { $this->parseTheNestedXML($element, $eachData); $eachData = $eachData[$element->getName()]; } else { $this->addValueToArray($key, $element, $eachData); } $eachData = $this->cleanArrayKeys($eachData); $allData[] = $eachData; $eachData = array(); } } else { $ret = $this->extractValue($xml, "//" . $xml->getName()); $eachData[$xml->getName()] = $ret; $allData[] = $eachData; } return $allData; } catch (Exception $e) { print "Something went wrong..\n"; echo $e->getMessage(); exit; } }
/** * Validate if children have same number of children. * @param SimpleXMLElement $complexDataXmlNode * @return boolean */ protected function _validateStructure($complexDataXmlNode) { if ($complexDataXmlNode->count() == 0) { return true; } $expectedChildren = null; $expectedChildrenCount = 0; foreach ($complexDataXmlNode->children() as $enumItem) { if ($expectedChildren == null) { /* @var $enumItemChild SimpleXMLElement */ foreach ($enumItem->children() as $nodeName => $enumItemChild) { $expectedChildrenCount++; $expectedChildren[$nodeName] = true; } continue; } if ($enumItem->count() != $expectedChildrenCount) { return false; } $compareFrom = Mage::helper('xmlimport')->xmlChildrenToArray($enumItem); if (count(array_diff_key($compareFrom, $expectedChildren)) != 0) { return false; } } return true; }
/** * @param \SimpleXMLElement $node * @param string $pseudoRegex * @param array $previousRegex * @return array */ protected function buildArray(\SimpleXMLElement $node, $pseudoRegex = '', array $previousRegex = []) { $routes = []; if ($node->count() > 0) { foreach ($node as $i => $routeXml) { $route = []; foreach ($routeXml->attributes() as $name => $attribute) { if ($name === 'match') { $regex = "{$pseudoRegex}/{$attribute}"; } else { if (in_array($name, ['module', 'controller', 'action'], true)) { $route['matches'][$name] = (string) $attribute; } else { if ($name === 'methods') { $route['methods'] = array_map('strtoupper', explode(',', (string) $attribute)); } else { $route['regex'][$name] = (string) $attribute; } } } } $currentRegex = isset($route['regex']) ? $route['regex'] : []; $route['regex'] = $currentRegex + $previousRegex; $routes[$regex] = $route; if ($routeXml->count() > 0) { $routes = array_merge($routes, $this->buildArray($routeXml, $regex, $route['regex'])); } } } return $routes; }
/** * Returns array representation of XML data, starting from a node pointed by * $node variable. * * Please see the documentation of this class for details about the internal * representation of XML data. * * @param \SimpleXMLElement $node A node to start parsing from * @return mixed An array representing parsed XML node or string value if leaf */ protected function parseNode(\SimpleXMLElement $node) { $parsedNode = []; if ($node->count() === 0) { return (string) $node; } foreach ($node->children() as $child) { $nameOfChild = $child->getName(); $parsedChild = $this->parseNode($child); if (count($child->attributes()) > 0) { $parsedAttributes = ''; foreach ($child->attributes() as $attributeName => $attributeValue) { if ($this->isDistinguishingAttribute($attributeName)) { $parsedAttributes .= '[@' . $attributeName . '="' . $attributeValue . '"]'; } } $nameOfChild .= $parsedAttributes; } if (!isset($parsedNode[$nameOfChild])) { // We accept only first child when they are non distinguishable (i.e. they differs only by non-distinguishing attributes) $parsedNode[$nameOfChild] = $parsedChild; } } return $parsedNode; }
public function sendAllSMS() { $dataArray = $this->getAuthData(); if (!$this->queue->count()) { return false; } $dataArray['action'] = 'xml_queue'; return $this->getAnswer((string) $this->httpClient->post($this->apiScript, ['query' => $dataArray, 'xml' => $this->queue->asXML()])->getBody()); }
/** * Parses XML response from AWIS and displays selected data * @param String $response xml response from AWIS */ public static function parseResponse($response) { $xml = new SimpleXMLElement($response, null, false, 'http://awis.amazonaws.com/doc/2005-07-11'); if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) { $info = $xml->Response->UrlInfoResult->Alexa; $nice_array = array('Phone Number' => $info->ContactInfo->PhoneNumbers->PhoneNumber, 'Owner Name' => $info->ContactInfo->OwnerName, 'Email' => $info->ContactInfo->Email, 'Street' => $info->ContactInfo->PhysicalAddress->Streets->Street, 'City' => $info->ContactInfo->PhysicalAddress->City, 'State' => $info->ContactInfo->PhysicalAddress->State, 'Postal Code' => $info->ContactInfo->PhysicalAddress->PostalCode, 'Country' => $info->ContactInfo->PhysicalAddress->Country, 'Links In Count' => $info->ContentData->LinksInCount, 'Rank' => $info->TrafficData->Rank); } foreach ($nice_array as $k => $v) { echo $k . ': ' . $v . "\n"; } }
function parse_countries_list() { $countries_xml = file_get_contents($this->user['folder'] . "/templates/countries.xml"); $xml = new SimpleXMLElement($countries_xml); $count = $xml->count(); $return = ""; for ($i = 0; $i < $count; $i++) { $return .= $xml->option[$i]->asXML(); } return $return; }
/** * @param \SimpleXMLElement $route * @param $name * @return array */ private function parseRouteParams(\SimpleXMLElement $route, string $name) { $params = []; if (!$route->count()) { return $params; } foreach ($route->param as $position => $param) { $params = array_merge($params, $this->parseRouteParam($name, $param, $position)); } return $params; }
public function getFlickrData() { $url = "https://api.flickr.com/services/feeds/photos_public.gne?tags=chamonix%2cski%2csnow"; $xmlFileData = file_get_contents($url); $xmlData = new SimpleXMLElement($xmlFileData); if ($xmlData->count() > 0) { $jsonData = json_encode($xmlData); return $jsonData; } return false; }
/** * Parses XML response from AWIS and displays selected data * @param String $response xml response from AWIS */ public static function parseResponse($response) { try { $xml = new SimpleXMLElement($response, null, false, 'http://awis.amazonaws.com/doc/2005-07-11'); if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) { $info = $xml->Response->UrlInfoResult->Alexa; return $info; } } catch (Exception $e) { echo 'Exception: ' . $response; exit; } }
public function makeUserTable() { $domains = isset($_POST['domain_list']) ? htmlspecialchars($_POST['domain_list']) : ''; $domainArray = array(); if ($domains !== '') { $domainsArray = explode("\n", $domains); } $userModel = new UserModel(); $userModel->cleanTable(); foreach ($domainsArray as $siteName) { $site = str_replace("\r", "", $siteName); $accessKeyId = "AKIAJGMJHABBXMYJDXTQ"; $secretAccessKey = "u2KzeMmzyymW0OyXTWcqukssiguYBWxe1otpkyhE"; $ActionName = 'UrlInfo'; $ResponseGroupName = 'Rank,ContactInfo,LinksInCount'; $ServiceHost = 'awis.amazonaws.com'; $NumReturn = 10; $StartNum = 1; $SigVersion = '2'; $HashAlgorithm = 'HmacSHA256'; $params = array('Action' => $ActionName, 'ResponseGroup' => $ResponseGroupName, 'AWSAccessKeyId' => $accessKeyId, 'Timestamp' => gmdate("Y-m-d\\TH:i:s.\\0\\0\\0\\Z", time()), 'Count' => $NumReturn, 'Start' => $StartNum, 'SignatureVersion' => $SigVersion, 'SignatureMethod' => $HashAlgorithm, 'Url' => $site); ksort($params); $keyvalue = array(); foreach ($params as $k => $v) { $keyvalue[] = $k . '=' . rawurlencode($v); } $queryParams = implode('&', $keyvalue); $sign = "GET\n" . strtolower($ServiceHost) . "\n/\n" . $queryParams; $sig1 = base64_encode(hash_hmac('sha256', $sign, $secretAccessKey, true)); $sig = rawurlencode($sig1); $url = 'http://' . $ServiceHost . '/?' . $queryParams . '&Signature=' . $sig; $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); $xml = new \SimpleXMLElement($result, null, false, 'http://awis.amazonaws.com/doc/2005-07-11'); if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) { $info = $xml->Response->UrlInfoResult->Alexa; $nice_array = array('Rank' => $info->TrafficData->Rank); } $rank = $nice_array['Rank']; //put into table $userModel = new UserModel(); $userModel->rank = $rank; $userModel->name = $site; $userModel->save(); } return redirect()->intended('domainTable'); }
/** * @Then I should see the correct sitemap elements * @And I should see the correct sitemap elements */ public function iShouldSeeTheCorrectSitemapElements() { // Grab sitemap.xml page contents and parse it as XML using SimpleXML library $sitemap_contents = $this->getSession()->getDriver()->getContent(); try { $xml = new SimpleXMLElement($sitemap_contents); } catch (Exception $e) { throw new Exception('Unable to read sitemap xml content - ' . $e->getMessage()); } // check if <url> nodes exist if (!($xml->count() > 0 && isset($xml->url))) { throw new InvalidArgumentException('No urlset found'); } }
/** * @param \SimpleXMLElement $element * @param string $locale * * @return string * * @throws \Exception */ protected function getLocalizedTagContent(\SimpleXMLElement $element, $locale = null) { if (0 === $element->count()) { return ''; } if (null === $locale) { return $this->multilineRemoveIndent((string) $element, 'true' === (string) $element->attributes()['removeIndent']); } foreach ($element as $node) { if ($locale == (string) $node->attributes()['locale']) { return $this->multilineRemoveIndent((string) $node, 'true' === (string) $node->attributes()['removeIndent']); } } $message = sprintf('Locale "%s" not available in node "%s".', $locale, $element->getName()); throw new \Exception($message); }
/** * @param \SimpleXMLElement $property * @param string $className * * @return PropertyCollectionSearchMetadata */ protected function getSearchMetadata(\SimpleXMLElement $property, $className) { $fieldElementAttributes = $property->attributes(); $field = (string) $fieldElementAttributes->{'field'}; $multipleSearchMetadata = $this->propertySearchMetadataFactory->createCollection($className, $field); if ($property->count() > 0) { foreach ($property->children() as $metadata) { $fieldElementAttributes = $metadata->attributes(); $propertyMetadata = $this->getPropertyMetadata($fieldElementAttributes, $className, $field); $multipleSearchMetadata->propertySearchMetadata[] = $propertyMetadata; } } else { $propertyMetadata = $this->getPropertyMetadata($fieldElementAttributes, $className, $field); $multipleSearchMetadata->propertySearchMetadata[] = $propertyMetadata; } return $multipleSearchMetadata; }
/** * @param SimpleXMLElement $node * @return array */ private function convertToArray(SimpleXMLElement $node) { $result = array(); $nodeData = array(); /** @var $attribute SimpleXMLElement */ foreach ($node->attributes() as $attribute) { $nodeData[$attribute->getName()] = (string) $attribute; } if ($node->count()) { $nodeData['node-value'] = array(); foreach ($node as $child) { $nodeData['node-value'][] = $this->convertToArray($child); } } else { $value = trim((string) $node); $nodeData['node-value'] = $value; } $result[$node->getName()] = $nodeData; return $result; }
/** * Get the XML data * * Returns an array of the XML data. If the XML data is just a single value it will return a string instead. * * @param \SimpleXMLElement $xml XML element * * @return array|string */ private function getData(\SimpleXMLElement $xml) { $data = array(); // loop through the attributes and append them to the data array with '-' prefix on keys foreach ($xml->attributes() as $key => $value) { $data['-' . $key] = (string) $value; } if ($xml->count() > 0) { $children = $xml->children(); // loop through the children foreach ($children as $key => $child) { $childData = $this->getData($child); // decide how to put this into the data array, if the key exists it becomes an array of values if (isset($data[$key])) { if (is_array($data[$key])) { $data[$key][] = $childData; } else { $data[$key] = array($data[$key], $childData); } } else { $data[$key] = array($childData); } } foreach ($data as $key => $value) { if (is_array($value) && count($value) === 1) { $data[$key] = $value[0]; } } } else { // get the string value of the XML $value = (string) $xml; // check if this is just a single value element, i.e. <Element>Value</Element> if (count($data) === 0) { $data = $value; } elseif (strlen((string) $xml)) { $data['#text'] = (string) $xml; } } return $data; }
/** * Extract info from the rows in a "Fields" or "Connections" table. * @param \SimpleXMLElement $rows * @return array */ function extractFields(\SimpleXMLElement $rows) { if ($rows->count() == 0 || $rows[0]->td->count() != 4) { // Not a "Name, Description, Permissions, Returns" table? return array(); } $fields = array(); foreach ($rows as $row) { if ($row->td[0]->b == 'Name') { continue; // Skip table header } $field = array('name' => strip_tags($row->td[0]->asXML()), 'description' => strip_tags($row->td[1]->children()->asXML()), 'permissions' => array(), 'returns' => strip_tags($row->td[3]->children()->asXML())); foreach ($row->td[2]->p->children()->code as $permission) { if (in_array((string) $permission, array('access_token'))) { continue; // skip "access_token" } $field['permissions'][] = (string) $permission; } $fields[$field['name']] = $field; } return $fields; }
/** * Convets SimpleXMLElement object to array * @param \SimpleXMLElement $element * @param boolean $ignoreAttributes [optional, default=false] * @return array */ public static function xml2array(\SimpleXMLElement $element, $ignoreAttributes = false) { $result = array(); if (!$ignoreAttributes) { foreach ($element->attributes() as $attr => $value) { $result['@attributes'][$attr] = (string) $value; } } $childrenCount = $element->count(); if ($childrenCount) { foreach ($element as $name => $child) { if ('' !== ($txt = trim((string) $child))) { $result[$name] = $txt; continue; } /* @var $child \SimpleXMLElement */ $childArray = self::xml2array($child, $ignoreAttributes); if (count($childArray) == 1 && array_key_exists($name, $childArray)) { $result[$name] = array_shift($childArray); } else { if ($childrenCount > count((array) $element)) { $result[] = $childArray; } else { $result[$name] = $childArray; } } } } else { if (isset($result['@attributes'])) { $result['@value'] = (string) $element; } else { return array($element->getName() => (string) $element); } } return $result; }
public function execute() { foreach ($this->arguments as $argument) { // Get the users.xml for each moodle backup $resultinfo = exec("unzip -p {$argument} users.xml ", $result, $validrun); echo "For Moodle backup {$argument} \r\n"; if (!$validrun) { $elem = new \SimpleXMLElement(implode("", $result)); $usercount = $elem->count(); echo "Number of Users is " . $usercount . "\r\n"; unset($elem, $result, $resultinfo); } else { echo "Sorry the local utility unzip is not available or the moodle backup {$argument} does not contain a users.xml file.\r\n"; } // Get the gradebook.xml for each moodle backup $resultinfo = exec("unzip -p {$argument} gradebook.xml ", $result, $validrun); if (!$validrun) { $elem = new \SimpleXMLElement(implode("", $result)); $gradecount = $elem->grade_items->grade_item->grade_grades->grade_grade->count(); echo "Number of Grades is " . $gradecount . "\r\n"; unset($elem, $result, $resultinfo); } else { echo "Sorry the Moodle backup {$argument} does not contain a gradebook.xml file.\r\n"; } // Get the course>logs.xml for each moodle backup $resultinfo = exec("unzip -p {$argument} course/logs.xml ", $result, $validrun); if (!$validrun) { $elem = new \SimpleXMLElement(implode("", $result)); $logcount = $elem->count(); echo "Number of Logs is " . $logcount . "\r\n"; unset($elem, $result, $resultinfo); } else { echo "Sorry the Moodle backup {$argument} does not contain a course>logs.xml file.\r\n"; } } }
/** * * Incorporta o XML a classe e seta os valores * * @param \SimpleXMLElement $xml * @return $this */ public function setUp(\SimpleXMLElement $xml) { $this->setStatus($xml->nivelRiscoAnaliseFraude); $this->setPontuacao($xml->scoreAnaliseFraude); $this->setRecomendacao($xml->recomendacaoAnaliseFraude); $this->setAcao($xml->acao); $this->setData($xml->dataAnaliseFraude); if ($xml->count() > 0) { foreach ($xml->listaDetalhesAnaliseFraude->detalhesAnaliseFraude as $subitem) { $this->addDetalhes($subitem); } } return $this; }
protected function recursiveRawDecode(array &$data, \SimpleXMLElement $node) { if ($node->count()) { if (!array_key_exists($node->getName(), $data)) { $data[$node->getName()] = []; } $row =& $data[$node->getName()]; foreach ($node->children() as $child) { $this->recursiveRawDecode($row, $child); } } else { $newRow = array(); /** @var SimpleXMLElement $attribute */ foreach ($node->attributes() as $attribute) { $newRow[$attribute->getName()] = $node->getAttributeAsPhp($attribute->getName()); } if ($node->getName() === $this->nodeName) { $data[] = $newRow; } else { $data[$node->getName()] = $newRow; } } }
/** * Recursively parse through XML, extract and save Department and Chapter data. * * @author Marcel de Vries * * @param array $out List of chapter ID's * @param SimpleXMLElement $root * @param int $index * @param array $data * @param int $parentId * * @return array */ private function _saveDepartmentChapter(&$out, &$root, $index = 0, $data = array(), $parentId = null) { $code = intval($root[$index]['NUMMER']); $desc = (string) $root[$index]['BESCHRIJVING']; $tmp = array(); if (count($root[$index]) === 0) { // AFDELING->HOOFDSTUKKEN->HOOFDSTUK $chapter = $this->Chapter->find('first', array('conditions' => array('Chapter.code' => $code), 'recursive' => -1)); $tmp['code'] = $code; $tmp['description'] = $desc; $tmp['parent_id'] = $parentId; $tmp['id'] = !empty($chapter) ? $chapter['Chapter']['id'] : null; $this->Chapter->create(); $this->Chapter->save($tmp); $out[] = $this->Chapter->id; $tmp['id'] = $this->Chapter->id; } else { $newRoot = $root[$index]->children(); if (!empty($code) && !empty($desc)) { // AFDELING $department = $this->Department->find('first', array('conditions' => array('Department.code' => $code), 'recursive' => -1)); $tmp['code'] = $code; $tmp['description'] = $desc; $tmp['id'] = !empty($department) ? $department['Department']['id'] : null; $this->Department->create(); $this->Department->save($tmp); $tmp['id'] = $this->Department->id; $tmp[] = $this->_saveDepartmentChapter($out, $newRoot, 0, array(), $this->Department->id); } else { // AFDELING->HOOFDSTUKKEN $tmp = $this->_saveDepartmentChapter($out, $newRoot, 0, array(), $parentId); } } $data[] = $tmp; if ($index < $root->count() - 1) { return $this->_saveDepartmentChapter($out, $root, ++$index, $data, $parentId); } else { return $data; } }
protected function get_xml_info($raw_info) { $xml = new SimpleXMLElement($raw_info, null, false, 'http://awis.amazonaws.com/doc/2005-07-11'); if ($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) { return $xml->Response->UrlInfoResult->Alexa; } else { return 1; } }
/** * Go through $root_el tree that represents the response from Netconf server. * * @param \SimpleXMLElement &$model with data model * @param \SimpleXMLElement $root_el with element of response * @param array $params modification parameters for merge */ public function mergeRecursive(&$model, $root_el, $params = array()) { if ($root_el->count() == 0) { $this->findAndComplete($model, $root_el, $params); // TODO: repair merge with root element (no parents) } foreach ($root_el as $ch) { $this->findAndComplete($model, $ch, $params); $this->mergeRecursive($model, $ch, $params); } foreach ($root_el->children as $ch) { $this->findAndComplete($model, $ch, $params); $this->mergeRecursive($model, $ch, $params); } }
/** * @param \SimpleXMLElement $xmlElement * @return \BolOpenApi\Model\Offers */ public function createOffers(\SimpleXMLElement $xmlElement) { $offers = new Offers(); if (!isset($xmlElement) || $xmlElement->count() <= 0) { return $offers; } foreach ($xmlElement->children() as $child) { if ($child->getName() == 'Offer') { $offers->addOffer($this->createOffer($child)); } if ($child->getName() == 'OfferTotals') { $offers->setOfferTotals($this->createOfferTotals($child)); } } return $offers; }
/** * Returns the numbers of nodes that the XML response has. * * @param type $response XML string. * @return int number of nodes. */ private function get_items_number($response) { if (is_null($response) || '' === trim($response)) { return 0; } $response = $this->sanitize_xml_string($response); $xml = new \SimpleXMLElement($response); $items_number = $xml->count(); return $items_number; }
//Get values required to perform function $username = $_POST["Username"]; $field = $_POST["Field"]; $returnData; //Data to return //If any values are null, return an error, otherwise continue. if ($username == null || $field == null) { echo "error_unknown"; exit; } //Load the XML file, and begin reading from it if (file_exists('users.xml')) { $xml = simplexml_load_file('users.xml'); $sxe = new SimpleXMLElement($xml->asXML()); for ($i = 0; $i < $sxe->count(); $i++) { if ($sxe->user[$i]->details->username == $username) { if ($field == "wins") { // Get wins $returnData = $sxe->user[$i]->score->wins; } else { if ($field == "losses") { // Get losses $returnData = $sxe->user[$i]->score->losses; } else { if ($field == "streaks") { // Get streaks $returnData = $sxe->user[$i]->score->streaks; } else { if ($field == "ratio") { $returnData = $sxe->user[$i]->score->ratio__string;
/** * Convert child nodes to array * * @param array $element * @param \SimpleXMLElement $node * @return array */ protected function convertChildNodes(array $element, \SimpleXMLElement $node) { if ($node->count() == 0) { $element[$node->getName()][] = $this->convertToArray($node); } else { foreach ($node->children() as $child) { $element = $this->convertChildNodes($element, $child); } } return $element; }
public function testXmlExport() { $this->logInAs('admin'); $client = $this->getClient(); // to be sure results are the same $contentInDB = $client->getContainer()->get('doctrine.orm.entity_manager')->getRepository('WallabagCoreBundle:Entry')->createQueryBuilder('e')->leftJoin('e.user', 'u')->where('u.username = :username')->setParameter('username', 'admin')->andWhere('e.isArchived = false')->getQuery()->getArrayResult(); ob_start(); $crawler = $client->request('GET', '/export/unread.xml'); ob_end_clean(); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; $this->assertEquals('application/xml', $headers->get('content-type')); $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); $content = new \SimpleXMLElement($client->getResponse()->getContent()); $this->assertGreaterThan(0, $content->count()); $this->assertEquals(count($contentInDB), $content->count()); $this->assertNotEmpty('id', (string) $content->entry[0]->id); $this->assertNotEmpty('title', (string) $content->entry[0]->title); $this->assertNotEmpty('url', (string) $content->entry[0]->url); $this->assertNotEmpty('content', (string) $content->entry[0]->content); $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); }
<?php //Set the default timezone date_default_timezone_set('UTC'); //Check if the file exists if (file_exists('../rss.xml') && file_exists("users.xml")) { //Load the files required $xmlRSS = simplexml_load_file('../rss.xml'); $sxeRSS = new SimpleXMLElement($xmlRSS->asXML()); $xmlUSR = simplexml_load_file('users.xml'); $sxeUSR = new SimpleXMLElement($xmlUSR->asXML()); //Get the current highest scores $maxWins = 0; for ($i = 0; $i < $sxeUSR->count(); $i++) { if ($maxWins < (int) $sxeUSR->user[$i]->score->wins) { $maxWins = $sxeUSR->user[$i]->score->wins; $maxWinsIndex = $i; } } $maxRatio = 0; for ($i = 0; $i < $sxeUSR->count(); $i++) { if ($maxRatio < (int) $sxeUSR->user[$i]->score->ratio) { $maxRatio = $sxeUSR->user[$i]->score->ratio; $maxRatioIndex = $i; } } $maxStreaks = 0; for ($i = 0; $i < $sxeUSR->count(); $i++) { if ($maxStreaks < (int) $sxeUSR->user[$i]->score->streaks) { $maxStreaks = $sxeUSR->user[$i]->score->streaks; $maxStreaksIndex = $i;