나는 php (codeigniter)로 개발 된 사이트를 가지고 있으며 동일한 구조의 배열을 병합하고 싶습니다. 이 내 배열의 생성자 :이 배열을 병합 할하지만 문제는 내가 그 안에 부분 배열을 가지고 내가 그런 독특한 배열을 만들려면복잡한 배열 PHP 병합
$first = array();
$first['hotel'] = array();
$first['room'] = array();
$first['amenities'] = array();
/*
Insert data into $first array
*/
$second = array();
$second['hotel'] = array();
$second['room'] = array();
$second['amenities'] = array();
/*
Insert data into $second array
*/
데이터를 삽입 한 후 :
$total = array();
$total['hotel'] = array();
$total['room'] = array();
$total['amenities'] = array();
을
$total = array_merge((array)$first, (array)$second);
나는 단지 $ 두 번째 배열하는 이유가이 배열에서 :
이 병합하는 시도이다? "입력 배열이 동일한 경우 : 그것은 array_merge처럼 보인다
<?php
$first = array();
$first['hotel'] = array('hello');
$first['room'] = array();
$first['amenities'] = array();
/*
Insert data into $first array
*/
$second = array();
$second['hotel'] = array('world');
$second['room'] = array();
$second['amenities'] = array();
$merged = array();
foreach($first as $key => $value)
{
$merged[$key] = array_merge($value, $second[$key]);
}
print_r($merged);
내가 당신의 –
원하는 출력을 찾고 원하는 출력에 대한 혼란 스러워요 처음 연구의 두 번째 좋아하지만 @SamuelCook –
합병 두 배열과 배열이 ['()'array_merge_recursive (HTTP를 찾고있을 수 있습니다 : // php.net/manual/en/function.array-merge-recursive.php)? – complex857