3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlstr = "<Feed> <Title>CompanyName</Title> <Email>info@CompanyName.com</Email> <Products> <Product> <Id>4635</Id> <Number>swv8813</Number> <Title><![CDATA[&Tradition - Bellevue AJ2 - Floor Lamp White]]></Title> <Description><![CDATA[]]></Description> <Category><![CDATA[Lighting]]></Category> <Stock>0</Stock> <Price>603.00</Price> <Discount>0.00</Discount> <Created>0000-00-00 00:00:00</Created> </Product> <Product> <Id>4635</Id> <Number>swv8814</Number> <Title><![CDATA[&Tradition - Bellevue AJ2 - Floor Lamp Black]]></Title> <Description><![CDATA[]]></Description> <Category><![CDATA[Lighting]]></Category> <Stock>0</Stock> <Price>900.00</Price> <Discount>0.00</Discount> <Created>0000-00-00 00:00:00</Created> </Product> </Products> </Feed>"; $feed = new SimpleXMLElement($xmlstr); function findPrice($feed, $id){ foreach($feed->Products->Product as $product){ if($product->Number == $id){ return $product->Price; } } return null; } echo findPrice($feed, 'swv8813'); echo "\n"; echo findPrice($feed, 'swv8814');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lT4Pl
function name:  (null)
number of ops:  17
compiled vars:  !0 = $xmlstr, !1 = $feed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3CFeed%3E%0A++++%3CTitle%3ECompanyName%3C%2FTitle%3E%0A++++%3CEmail%3Einfo%40CompanyName.com%3C%2FEmail%3E%0A++++%3CProducts%3E%0A++++++++++++%3CProduct%3E%0A++++++++++++++++%3CId%3E4635%3C%2FId%3E%0A++++++++++++++++%3CNumber%3Eswv8813%3C%2FNumber%3E%0A++++++++++++++++%3CTitle%3E%3C%21%5BCDATA%5B%26Tradition+-+Bellevue+AJ2+-+Floor+Lamp+White%5D%5D%3E%3C%2FTitle%3E%0A++++++++++++++++%3CDescription%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C%2FDescription%3E%0A++++++++++++++++%3CCategory%3E%3C%21%5BCDATA%5BLighting%5D%5D%3E%3C%2FCategory%3E%0A++++++++++++++++%3CStock%3E0%3C%2FStock%3E%0A++++++++++++++++%3CPrice%3E603.00%3C%2FPrice%3E%0A++++++++++++++++%3CDiscount%3E0.00%3C%2FDiscount%3E%0A++++++++++++++++%3CCreated%3E0000-00-00+00%3A00%3A00%3C%2FCreated%3E%0A++++++++++++%3C%2FProduct%3E%0A++++++++++++%3CProduct%3E%0A++++++++++++++++%3CId%3E4635%3C%2FId%3E%0A++++++++++++++++%3CNumber%3Eswv8814%3C%2FNumber%3E%0A++++++++++++++++%3CTitle%3E%3C%21%5BCDATA%5B%26Tradition+-+Bellevue+AJ2+-+Floor+Lamp+Black%5D%5D%3E%3C%2FTitle%3E%0A++++++++++++++++%3CDescription%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C%2FDescription%3E%0A++++++++++++++++%3CCategory%3E%3C%21%5BCDATA%5BLighting%5D%5D%3E%3C%2FCategory%3E%0A++++++++++++++++%3CStock%3E0%3C%2FStock%3E%0A++++++++++++++++%3CPrice%3E900.00%3C%2FPrice%3E%0A++++++++++++++++%3CDiscount%3E0.00%3C%2FDiscount%3E%0A++++++++++++++++%3CCreated%3E0000-00-00+00%3A00%3A00%3C%2FCreated%3E%0A++++++++++++%3C%2FProduct%3E%0A++++%3C%2FProducts%3E%0A%3C%2FFeed%3E'
   31     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   42     5        INIT_FCALL                                               'findprice'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'swv8813'
          8        DO_FCALL                                      0  $6      
          9        ECHO                                                     $6
   43    10        ECHO                                                     '%0A'
   44    11        INIT_FCALL                                               'findprice'
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 'swv8814'
         14        DO_FCALL                                      0  $7      
         15        ECHO                                                     $7
         16      > RETURN                                                   1

Function findprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/lT4Pl
function name:  findPrice
number of ops:  16
compiled vars:  !0 = $feed, !1 = $id, !2 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        FETCH_OBJ_R                                      ~3      !0, 'Products'
          3        FETCH_OBJ_R                                      ~4      ~3, 'Product'
          4      > FE_RESET_R                                       $5      ~4, ->13
          5    > > FE_FETCH_R                                               $5, !2, ->13
   35     6    >   FETCH_OBJ_R                                      ~6      !2, 'Number'
          7        IS_EQUAL                                                 !1, ~6
          8      > JMPZ                                                     ~7, ->12
   36     9    >   FETCH_OBJ_R                                      ~8      !2, 'Price'
         10        FE_FREE                                                  $5
         11      > RETURN                                                   ~8
   34    12    > > JMP                                                      ->5
         13    >   FE_FREE                                                  $5
   39    14      > RETURN                                                   null
   40    15*     > RETURN                                                   null

End of function findprice

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.54 ms | 1407 KiB | 15 Q