N
N
nonvon2018-01-15 17:24:07
Iron
nonvon, 2018-01-15 17:24:07

Php simplexml gives different results, why?

I can’t collect sizes with a quantity in one array, more precisely on a local machine of norms

<offer>
<avail quantity="25">
<size quantity="5">S</size>
<size quantity="8">M</size>
<size quantity="13">L</size>
<size quantity="5">XL</size>
</avail>
</offer>

$attrs = $offer->avail->size;	
    foreach ($attrs as $key => $attr) 		  
      if ( ($key == 'size') and (!empty($attr)) )		
      {  
        $arr = (array)$attr;
        $tSizes[$arr[0]] = $arr["@attributes"]["quantity"];  
      }

object(SimpleXMLElement)#10 (2) {
  ["@attributes"]=>
  array(1) {
    ["quantity"]=>
    string(1) "5"
  }
  [0]=>
  string(1) "S"
}
object(SimpleXMLElement)#11 (2) {
  ["@attributes"]=>
  array(1) {
    ["quantity"]=>
    string(1) "8"
  }
  [0]=>
  string(1) "M"
}
object(SimpleXMLElement)#10 (2) {
  ["@attributes"]=>
  array(1) {
    ["quantity"]=>
    string(2) "13"
  }
  [0]=>
  string(1) "L"
}
object(SimpleXMLElement)#11 (2) {
  ["@attributes"]=>
  array(1) {
    ["quantity"]=>
    string(1) "5"
  }
  [0]=>
  string(2) "XL"
}

and on the server the part with the size disappears
[0]=>
string(1) "S"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex F, 2019-11-02
@delvin-fil

Interesting mom.
Cleaning the mother, she is such a cleaning ...
A) return the old vidyakha and try to turn it on without hdd .
B) Check ALL connections! It's better to remove everything (except for the processor) and stick it again.

connected to laptop, not readable
Doesn't fit how? Does the BIOS see it?

N
nonvon, 2018-01-15
@nonvon

foreach ($offer->avail->size as $key => $attr) 	  
     if ( ($key == 'size') and (!empty($attr)) )		
       $tSizes[(string)$attr] = (string)$attr['quantity'];

always cast to type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question