2016-03-08 47 views
-4

所有數組值I具有打印在變量$ ARRAY1所有值如何打印在PHP

<?php 
    $array1 = array(10,11,12,13,14,"hello", array(1,2,3,4)); 
    print_r ($array1) 
?> 

輸出

陣列([0] => 10 [1] => 11 [2 ] => 12 [3] => 13 [4] => 14 [5] => hello [6] =>陣列([0] => 1 [1] => 2 [2] => 3 [3] => 4))

但我一次僅打印數組(1,2,3,4)的值。

+0

打印的print_r($數組1 [6]); – Deep

+0

你的意思是說你只想在'$ array1'的出現'[6]'中打印子數組? – RiggsFolly

回答

-1

如果你不知道哪個是數組..

foreach ($array1 as $value) 
    if (is_array($value)) 
     print_r($value); 
+0

對不起爲什麼投下了票?這是根據請求做的,但不必指定數組所在的索引 – Barry

0

請試試這個

foreach ($array1 as $value){ 
    if (is_array($value)){ // Check the value is an array or not 
     $subArr = $value; 
    } 
} 

echo "Sub array value is :"; 
print_r($subArr); 
0

您可以嘗試使用implode陣列功能。

E.g.

print_r(implode(",",$array1[6])); 

結果: 1,2,3,4-

0
try it get the count of the array and print the array in for loop 
    <?php 
     $array1 = array(10,11,12,13,14,"hello"); 
     $count=count($array1); 
     for($i=0;$i<$count;$i++) 
     { 
      echo $array1[$i]; 
      echo '<br/>'; 
     } 
    ?>