rossmurphy Posted October 7, 2009 Share Posted October 7, 2009 Hi all, I am using the simplexml_load_file() function to load x2 xml files from an api call. So i have x2 object arrays which i want to combine into one. I am unsure how to combine these two arrays. I have tried using array_merge() and array_combine but i get an error 'argument1 not an array, argument 2 not an array'. Does anyone know how i would go about this? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/176823-combinemerge-x2-or-more-arrays/ Share on other sites More sharing options...
salathe Posted October 7, 2009 Share Posted October 7, 2009 The items that you're trying to merge are not arrays, so the error says. What precisely are you trying to merge (a code snippet for us to reproduce the problem is generally useful)? Link to comment https://forums.phpfreaks.com/topic/176823-combinemerge-x2-or-more-arrays/#findComment-932306 Share on other sites More sharing options...
rossmurphy Posted October 7, 2009 Author Share Posted October 7, 2009 Sorry, meant to add snippet. Here is an example of what i returned to me via the simplexml_load_fiile()... SimpleXMLElement Object ( [metadata] => SimpleXMLElement Object ( [column] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => gameSource ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => gameName ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => gameSource ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => gameType ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => gameCurrency ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => text [name] => style ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => configId ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => denominations ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => minBet ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => maxBet ) ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => minCoins ) ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [datatype] => number [name] => maxCoins ) ) ) ) [rows] => SimpleXMLElement Object ( [row] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 12 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => 10s or Better [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => 10s or Better [style] => TENS ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 1 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => All American [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => All American [style] => ALLA ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 2 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Bonus Poker [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Bonus Poker [style] => BONP ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 3 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Bonus Poker Deluxe [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Bonus Poker Deluxe [style] => BOPD ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 4 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Deuces & Jokers [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Deuces & Jokers [style] => DEUJ ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 5 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Deuces Wild [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Deuces Wild [style] => DEUW ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 6 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Double Bonus [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Double Bonus [style] => DOUB ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 7 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Double Joker [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Double Joker [style] => DOUJ ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 8 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Jacks or Better [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Jacks or Better [style] => JOB1 ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 9 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Jacks or Better - 10 Line [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Jacks or Better 10 Line [style] => JOBT ) ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 10 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Jacks or Better - 50 Line [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Jacks or Better 50 Line [style] => JOBF ) ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [configId] => 11 [denominations] => 0.05, 0.25, 0.5, [gameCurrency] => USD [gameName] => Joker Poker [gameSource] => parlay [gameType] => PK [maxBet] => 0.5 [maxCoins] => 0 [minBet] => 0.05 [minCoins] => 0 [screenName] => Joker Poker [style] => JOKP ) ) ) ) ) So i have x2 of these that have exactly the same attribues and fields, just different values. I want to merge them. Link to comment https://forums.phpfreaks.com/topic/176823-combinemerge-x2-or-more-arrays/#findComment-932313 Share on other sites More sharing options...
salathe Posted October 7, 2009 Share Posted October 7, 2009 Merge them or just combine them into a single object with all of the values (ie, append one to the other)? Merging suggests you want some overlapping values to be overwritten (like array_merge). Samples of the XML would also make life easier than working with print_r output. Link to comment https://forums.phpfreaks.com/topic/176823-combinemerge-x2-or-more-arrays/#findComment-932369 Share on other sites More sharing options...
rossmurphy Posted October 7, 2009 Author Share Posted October 7, 2009 i would like to append one to the end of the other so i don't have to loop through 2 separate ones. here is the xml <rows> <row configId="26" denominations="null" gameCurrency="EUR" gameName="CashInn" gameSource="DYNAMITE" gameType="SL" maxBet="0.0" maxCoins="0" minBet="0.0" minCoins="1" screenName="The Cash Inn" style="CI"/> <row configId="27" denominations="null" gameCurrency="EUR" gameName="GoldRush" gameSource="DYNAMITE" gameType="SL" maxBet="0.0" maxCoins="0" minBet="0.0" minCoins="1" screenName="Gold Rush" style="GR"/> <row configId="28" denominations="null" gameCurrency="EUR" gameName="OoohMatronUK" gameSource="DYNAMITE" gameType="SL" maxBet="0.0" maxCoins="0" minBet="0.0" minCoins="1" screenName="Oooh Matron" style="OM"/> <row configId="29" denominations="null" gameCurrency="EUR" gameName="SportsCrazyUK" gameSource="DYNAMITE" gameType="SL" maxBet="0.0" maxCoins="0" minBet="0.0" minCoins="1" screenName="Sports Crazy" style="SP"/> </rows> Link to comment https://forums.phpfreaks.com/topic/176823-combinemerge-x2-or-more-arrays/#findComment-932381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.