简体   繁体   中英

Get next value in PHP

In an XML file i have some attributes

<logoSize logoSizeCm2="6">
<logoSize logoSizeCm2="24">
<logoSize logoSizeCm2="60">
<logoSize logoSizeCm2="120">
<logoSize logoSizeCm2="240">

What i want is to get every logoSizeCm2 value that is lower than $prpurlNumber plus the next one.

foreach ($XMLB->logoSize as $prodar) {
   $prodb = $prodar[0];
   $pripurl = $prodb->xpath("@logoSizeCm2");
   $prpurlNumber = '65';
   if ($pripurl <= $prpurlNumber) {
      echo $prpurl;
   }
}

This outputs 6 24 60 but what i want is to also get the next one like this 6 24 60 120 Any help would be much appreciated.

If they will always be in ascending order

$prpurlNumber = '65';
foreach ($XMLB->logoSize as $prodar) {
    $prodb = $prodar[0];
    $pripurl = $prodb->xpath("@logoSizeCm2");
   
    if ($pripurl <= $prpurlNumber) {
        echo $prpurl;
    }
    if ($pripurl > $prpurlNumber) {
        echo $prpurl;
        break;  // to exit the loop
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM