2010-12-30 2 views
1

이 경우 도와주세요. Habax의 스크립트를 기반으로배열은 도움말의 순서를 바꾸고 도움말을 대체합니다. (키와 값을 새 배열로)

Array 
(
[list] => Array // if the (array's name = `list`) the array[#][parent_id] = null 
    (
     [0] => 1 // the key of the array (`[0]` in this case) is the array[#][order_id] 
     [1] => 2 // the value of the array (`2` in this case) is the array[#][id] 
     [2] => 5 
    ) 

[list_2] => Array // else the array[#][parent_id] = the number value after the _ 
    (
     [0] => 3 
     [1] => 4 
    ) 

[list_5] => Array 
    (
     [0] => 6 
    ) 
) 

좋은 솔루션 :이처럼 나는 배열을 가지고, 나는

array[0][id] = 1 
array[0][parent_id] = null 
array[0][order_id] = 1 
array[1][id] = 2 
array[1][parent_id] = null 
array[1][order_id] = 2 
etc. 

나의 현재 배열처럼, 새로운 것을하고 싶습니다http://www.b-hind.eu/jquery/

: 같은 중첩 된 sortables을 주선

$new = array(); 
$n=0; 
foreach($old as $key=>$item){ 
    for ($i = 1; $i <= count($item); $i++) { 
     if($key=='list')$new[$n]['parent_id']=null; 
     else { 
      $tmp = explode('_', $key); 
      $new[$n]['parent_id']=$tmp[1]; 
     } 
     $new[$n]['order_id']=$i; 
     $new[$n]['id']=$item[$i-1]; 
     $n++; 
    } 
} 
} 

좋은 16,

답변

2

내가이 키 값이 아닌,의 가정 것이다 라인을

[0] => 1 // the key of the array (`[0]` in this case) is the array[#][order_id] 

을 이해 쉬르 아니에요 : 내가 그 경우에 의미

$new = array(); 
$n=0; 
foreach($old as $key=>$item){ 
    if($key=='list')$new[$n]['parent_id']=null; 
    else { 
    $tmp = explode('_', $key); 
    $new[$n]['parent_id']=$tmp[1]; 
    } 
    $new[$n]['order_id']=$item[0]; 
    $new[$n]['id']=$item[1]; 
    $n++; 
} 
+0

배열 [#] [ORDER_ID] = 0, yes : P –

+0

order_id가 0이 아닌 경우가 있습니까? – Habax

+0

예. list_N : [order_id] => id : [0] => 3, [1] => 4. 그리고 배열의 모든 요소가 필요합니다. 스크립트에서 일부 chaging을 만들었습니다. : P –

관련 문제