merge two arrays into one array

zym120

New Member
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:\[code\]<?php$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw"; $xml = simplexml_load_file($url); $xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');$textNode = $xml->xpath("//default:RichText[@s7:elementID]");function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }$result = array();$result1 = array();foreach($textNode as $node){ $result[] = $node->attributes('http://ns.adobe.com/S7FXG/2008'); $result1[] = $node->attributes();}$text = array_merge($result,$result1);pr($text);?>\[/code\]OUTPUT\[code\]Array( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [caps] => none [colorName] => [colorValue] => #518269 [colorspace] => rgb [elementID] => smalltext [fill] => true [fillOverprint] => false [firstBaselineOffset] => ascent [joints] => miter [maxFontSize] => 11 [miterLimit] => 4 [referencePoint] => inherit [rowCount] => 1 [rowGap] => 18 [rowMajorOrder] => true [stroke] => false [strokeOverprint] => false [warpBend] => 0.5 [warpDirection] => horizontal [warpHorizontalDistortion] => 0 [warpStyle] => none [warpVerticalDistortion] => 0 [weight] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [caps] => none [colorName] => [colorValue] => #518269 [colorspace] => rgb [elementID] => largetext [fill] => true [fillOverprint] => false [firstBaselineOffset] => ascent [joints] => miter [maxFontSize] => 19 [miterLimit] => 4 [referencePoint] => inherit [rowCount] => 1 [rowGap] => 18 [rowMajorOrder] => true [stroke] => false [strokeOverprint] => false [warpBend] => 0.5 [warpDirection] => horizontal [warpHorizontalDistortion] => 0 [warpStyle] => none [warpVerticalDistortion] => 0 [weight] => 1 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.418 [y] => 115.542 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Trade Gothic LT Pro Bold Cn [fontSize] => 11 [color] => #518269 [whiteSpaceCollapse] => preserve [width] => 212.582 [height] => 33 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [x] => 278.998 [y] => 86.7168 [columnGap] => 18 [columnCount] => 1 [textAlign] => left [fontFamily] => Bootstrap [fontSize] => 19 [color] => #518269 [whiteSpaceCollapse] => preserve [trackingRight] => 4% [width] => 240 [height] => 29 ) ))\[/code\]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.Is this possible?
 
Back
Top