Note that there are some explanatory texts on larger screens.

plurals
  1. POmerge two arrays into one array
    primarykey
    data
    text
    <p>i have the following code that creates two arrays for each <code>RichText</code> element in my xml source. One of the arrays is for an attribute with a prefix, and the other array is for the attributes that do not have any prefixes. This is the only way I could figure out how to do it:</p> <pre><code>&lt;?php $url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&amp;fmt=fxgraw"; $xml = simplexml_load_file($url); $xml-&gt;registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008'); $xml-&gt;registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008'); $textNode = $xml-&gt;xpath("//default:RichText[@s7:elementID]"); function pr($var) { print '&lt;pre&gt;'; print_r($var); print '&lt;/pre&gt;'; } $result = array(); $result1 = array(); foreach($textNode as $node){ $result[] = $node-&gt;attributes('http://ns.adobe.com/S7FXG/2008'); $result1[] = $node-&gt;attributes(); } $text = array_merge($result,$result1); pr($text); ?&gt; </code></pre> <p><strong>OUTPUT</strong></p> <pre><code>Array ( [0] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [caps] =&gt; none [colorName] =&gt; [colorValue] =&gt; #518269 [colorspace] =&gt; rgb [elementID] =&gt; smalltext [fill] =&gt; true [fillOverprint] =&gt; false [firstBaselineOffset] =&gt; ascent [joints] =&gt; miter [maxFontSize] =&gt; 11 [miterLimit] =&gt; 4 [referencePoint] =&gt; inherit [rowCount] =&gt; 1 [rowGap] =&gt; 18 [rowMajorOrder] =&gt; true [stroke] =&gt; false [strokeOverprint] =&gt; false [warpBend] =&gt; 0.5 [warpDirection] =&gt; horizontal [warpHorizontalDistortion] =&gt; 0 [warpStyle] =&gt; none [warpVerticalDistortion] =&gt; 0 [weight] =&gt; 1 ) ) [1] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [caps] =&gt; none [colorName] =&gt; [colorValue] =&gt; #518269 [colorspace] =&gt; rgb [elementID] =&gt; largetext [fill] =&gt; true [fillOverprint] =&gt; false [firstBaselineOffset] =&gt; ascent [joints] =&gt; miter [maxFontSize] =&gt; 19 [miterLimit] =&gt; 4 [referencePoint] =&gt; inherit [rowCount] =&gt; 1 [rowGap] =&gt; 18 [rowMajorOrder] =&gt; true [stroke] =&gt; false [strokeOverprint] =&gt; false [warpBend] =&gt; 0.5 [warpDirection] =&gt; horizontal [warpHorizontalDistortion] =&gt; 0 [warpStyle] =&gt; none [warpVerticalDistortion] =&gt; 0 [weight] =&gt; 1 ) ) [2] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [x] =&gt; 278.418 [y] =&gt; 115.542 [columnGap] =&gt; 18 [columnCount] =&gt; 1 [textAlign] =&gt; left [fontFamily] =&gt; Trade Gothic LT Pro Bold Cn [fontSize] =&gt; 11 [color] =&gt; #518269 [whiteSpaceCollapse] =&gt; preserve [width] =&gt; 212.582 [height] =&gt; 33 ) ) [3] =&gt; SimpleXMLElement Object ( [@attributes] =&gt; Array ( [x] =&gt; 278.998 [y] =&gt; 86.7168 [columnGap] =&gt; 18 [columnCount] =&gt; 1 [textAlign] =&gt; left [fontFamily] =&gt; Bootstrap [fontSize] =&gt; 19 [color] =&gt; #518269 [whiteSpaceCollapse] =&gt; preserve [trackingRight] =&gt; 4% [width] =&gt; 240 [height] =&gt; 29 ) ) ) </code></pre> <p>My <code>array_merge</code> after the loop creates one huge array, with 4 nested arrays. Two arrays are the default attributes of <code>RichText</code>, and the other two arrays are the attributes that have a <code>s7:</code> prefix. But what I need is that <code>$result</code> and <code>$result1</code> be merged inside the foreach loop, that way there is just one merged array for each <code>$textNode</code> containing all the attributes. Thus, in this example url I should have two arrays in the end because there are only two <code>RichText</code> elements.</p> <p>Is this possible?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload