slanton Posted June 19, 2006 Share Posted June 19, 2006 I want to merge two arrays and the following works as I want [code]<?php $book1=array(alphabet => array('a','b','c')); $book2=array(alphabet => array('d','e','f')); $book3 = array_merge_recursive($book1, $book2); print_r($book3); ?>//returnsArray ( [alphabet] => Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f ) ) [/code]but if the key is numeric it doesn't work as I want[code]<?php $book1=array(101 => array('a','b','c')); $book2=array(101 => array('d','e','f')); $book3 = array_merge_recursive($book1, $book2); print_r($book3); ?>//returnsArray ( [0] => Array ( [0] => a [1] => b [2] => c ) [1] => Array ( [0] => d [1] => e [2] => f ) )[/code]How can I get the numeric merge to return[code]Array ( [101] => Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f ) ) [/code] Link to comment https://forums.phpfreaks.com/topic/12341-merging-arrays/ Share on other sites More sharing options...
poirot Posted June 19, 2006 Share Posted June 19, 2006 Changing these:[code] $book1=array(101 => array('a','b','c')); $book2=array(101 => array('d','e','f'));[/code]To[code] $book1=array('101' => array('a','b','c')); $book2=array('101' => array('d','e','f'));[/code]*should* do the trick. Link to comment https://forums.phpfreaks.com/topic/12341-merging-arrays/#findComment-47166 Share on other sites More sharing options...
slanton Posted June 19, 2006 Author Share Posted June 19, 2006 Yes I had tried that as well because the recursive merge only works that way with strings but it didn't work when I tried that which puzzles me. Shouldn't putting the numbers between '' make them into a string? Link to comment https://forums.phpfreaks.com/topic/12341-merging-arrays/#findComment-47172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.