2013-12-17 44 views
-4

此循環只給出輸出Array而不是當我使用print_r函數時顯示的值。回聲陣列只是給出輸出數組而不是值

print_r給了我這樣的:

Array 
(
    [0] => 1 
    [1] => 2 
    [2] => 3 
    [3] => 1 
) 

但回聲只是陣列

for($i=0; $i<($n*$n); $i++){ 

     for($j=0; $j<($n*$n); $j++){ 
     $number = "column" . $i . $j; 
     $plan = $field[$i][$j] = $_POST[$number]; 
     $myvariable[] = $field[$i][$j]; 

     } 
     echo $myvariable; 
    } 

,但如果我從$myvariable刪除[]它打印出的值。問題是我需要使用具有獨特陣列的陣列

$unique = array_unique($myvariable); 
    if (count($unique) != count($myvariable)) { 
echo ="no uniques"; 

} 

任何提示?

+0

其實很困惑的你到底想達到此 –

+0

我還是不理解,但我想你想要的是什麼是循環通過獨特的'數組',所以讓你的'數組'唯一的第一個,並通過 –

+0

循環是否有你想/需要在你的循環回聲的原因? – Sean

回答

2

您的意思是?

$unique = array_unique($myvariable); 
foreach($unique as $value) 
{ 
echo $value; 
} 

或使用的典型for

$unique = array_unique($myvariable); 
for($i=0;$i<count($unique);$i++) 
{ 
echo $unique[$i]; 
} 
+2

這就是我正在試圖做的。非常感謝你,我的朋友 – Dymond