2012-07-10 2 views
2

문제는 ...이처럼다음에 그것을

기존의 배열 :

Array(
    [0] => array('sample 1', 'sample 2') 
    [1] => array('cat', 'dog') 
) 

또 다른 배열 : I가 발생하는 것이

Array(
    [0] => array('sample 3', 'sample 4') 
) 

0 키 옆에 추가하면 다음과 같이됩니다.

Array(
    [0] => array('sample 1', 'sample 2') 
    [1] => array('sample 3', 'sample 4') 
    [2] => array('cat', 'dog') 
) 

어떻게 할 수 있습니까?

다음
Array(
[0] => sample 1 
[1] => sample 2 
[2] => sample 3 
[3] => sample 4 
[4] => cat 
[6] => dog 
) 

내 현재의 현재의 코드

$new_post_order = array(); 
foreach($the_query['posts'] as $the_post) { 
$portfolio_reorder = ''; 
$portfolio_reorder = get_post_meta($the_post['ID'], 'portfolio_reorder', true); // Get the order on the db 
if(empty($portfolio_reorder)) { // If its empty... 
$portfolio_reorder = 0; // Add default order       
} 
array_splice($new_post_order, $portfolio_reorder, 0, $the_post); 
} 

echo '<pre>'; 
print_r($new_post_order); 
echo '</pre>'; 

답변

5

당신이 array_splice으로이 작업을 수행 :

내가하지만 그것을 시도하고 그 결과는 다음과 같이이다 @maxhud

http://php.net/manual/en/function.array-splice.php

예 충분 :

$input = array("red", "green", "blue", "yellow"); 
array_splice($input, 3, 0, "purple"); 
// $input is now array("red", "green", 
//   "blue", "purple", "yellow"); 

직접 시도해보십시오. 알아낼 수없는 경우 의견을 보내 주시면 Google에서 도와 드리겠습니다.

array_splice($new_post_order, $portfolio_reorder, 0, array($the_post)); 
+0

Maxhud 내 질문을 편집했습니다. 내 발췌 부분을 잘 보살펴주세요. 감사! – Ian

+0

은 귀하의 예에서 언급 한 '샘플'에 해당하는 $ the_post입니까? 의미, $ the_post 변수 저장소는 무엇입니까? 두 개의 항목 또는 문자열이있는 배열입니까? – maxhud

+0

$ the_post 변수는 배열입니다. – Ian

관련 문제