deneme - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of deneme.php

  1. <?php
  2. error_reporting(E_ERROR | E_PARSE);
  3. $xml = simplexml_load_file("parent.xml");
  4. $parent = unserialize(serialize(json_decode(json_encode((array) $xml), 1)));
  5. $donen = unserialize(serialize(json_decode(json_encode((array) $xml), 1)));
  6. $xmls = simplexml_load_file("variable.xml");
  7. $varyant = unserialize(serialize(json_decode(json_encode((array) $xmls), 1)));
  8.  
  9.  
  10. foreach($varyant["post"] as $k => $urun ){
  11.    
  12.     $type = $urun["ProductType"];
  13.     if($type=="variable"){
  14.  
  15.         foreach($parent["post"] as $ks => $vs ){
  16.  
  17.             if($urun["ParentProductID"] == $vs["id"]){
  18.  
  19.                 $donen["post"][$ks]["AltVaryant"]["post"][] = $varyant["post"][$k];
  20.  
  21.  
  22.             }
  23.  
  24.         }
  25.  
  26.  
  27.     }
  28.     
  29. }
  30. // XML BUILD RECURSIVE FUNCTION
  31. function array_to_xml($array, &$xml) {        
  32.     foreach($array as $key => $value) {               
  33.         if(is_array($value)) {            
  34.             if(!is_numeric($key)){
  35.                 $subnode = $xml->addChild($key);
  36.                 array_to_xml($value, $subnode);
  37.             } else {
  38.                 array_to_xml($value, $subnode);
  39.             }
  40.         } else {
  41.             $xml->addChild($key, $value);
  42.         }
  43.     }        
  44. }
  45.  
  46. $stringdonen = "";
  47. $xmlcevirici = array();
  48. $sayi = 0;
  49. foreach($donen["post"] as $k => $v){
  50.     if(isset($v["AltVaryant"])){
  51.         //print_r($v["AltVaryant"]);
  52.         $varyantlistesi = array();
  53.         foreach($v["AltVaryant"]["post"] as $b => $c){
  54.             $varyantlistesi["altvaryantlar".$b] = array(
  55.  
  56.                 "key" => $b,
  57.                 "keys" => $b,
  58.                 "keyc" => $b,
  59.                 
  60.  
  61.             );
  62.  
  63.         }
  64.         $add = array(
  65.             "id" => $v["id"],
  66.             "SKU" => $v["SKU"],
  67.             "ProductType" => $v["ProductType"],
  68.             "Stock" => $v["Stock"],
  69.             "AltVaryant" => $varyantlistesi,
  70.             "resim" => $v["resim"]
  71.                    
  72.         );
  73.     
  74.     }else{
  75.     //echo $v["id"];
  76.     $add = array(
  77.  
  78.         "id" => $v["id"],
  79.         "SKU" => $v["SKU"],
  80.         "ProductType" => $v["ProductType"],
  81.         "Stock" => $v["Stock"],
  82.         "resim" => $v["resim"]
  83.                
  84.     );
  85.     $xml = new SimpleXMLElement('<post/>'); 
  86.     array_to_xml($add, $xml);
  87.     
  88.     // TO PRETTY PRINT OUTPUT
  89.     $domxml = new DOMDocument('1.0');
  90.     $domxml->preserveWhiteSpace = false;
  91.     $domxml->formatOutput = true;
  92.     $domxml->loadXML($xml->asXML());
  93.     
  94.     $stringdonen .= $domxml->saveXML();
  95.     
  96.     
  97. }
  98.     $xmlcevirici["Project".$sayi.""] = $add;
  99.     
  100. $sayi++;
  101.  
  102. }
  103.  
  104. $xml = new SimpleXMLElement('<post/>'); 
  105. array_to_xml($xmlcevirici, $xml);
  106.  
  107. // TO PRETTY PRINT OUTPUT
  108. $domxml = new DOMDocument('1.0');
  109. $domxml->preserveWhiteSpace = false;
  110. $domxml->formatOutput = true;
  111. $domxml->loadXML($xml->asXML());
  112.  
  113. $stringdonen .= $domxml->saveXML();
  114.  
  115. $stringdonen = $strintdonen;
  116. ?>
File Description
  • deneme
  • PHP Code
  • 03 May-2021
  • 2.76 Kb
You can Share it: