2011-01-28 21 views
0

マイ配列:フィルタアレイ結果

<?php 

$hoppa = array 
(
    "0" => array 
     ("0","0","0","0","0","0","0","0","0","0"), 
    "1" => array 
     ("0","0","0","0","0","0","0","0","0","0"),  
    "2" => array 
     ("1","0","0","1","0","0","0","0","0","0"), 
    "3" => array 
     ("1","0","0","1","0","1","1","1","1","0"), 
    "4" => array 
     ("1","1","1","1","0","0","0","0","1","0"), 
    "5" => array 
     ("1","0","0","1","0","1","1","1","1","0"), 
    "6" => array 
     ("1","0","0","1","0","1","0","0","1","0"), 
    "7" => array 
     ("1","0","0","1","0","1","1","1","1","0"), 
    "8" => array 
     ("0","0","0","0","0","0","0","0","0","0"), 
    "9" => array 
     ("0","0","0","0","0","0","0","0","0","0")         

); 

?> 

マイアレイの出力:

Array 
(
    [0] => Array 
     (
      [0] => 0 
      [1] => 0 
      [2] => 0 
      [3] => 0 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 0 
      [9] => 0 
     ) 

    [1] => Array 
     (
      [0] => 0 
      [1] => 0 
      [2] => 0 
      [3] => 0 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 0 
      [9] => 0 
     ) 

    [2] => Array 
     (
      [0] => 1 
      [1] => 0 
      [2] => 0 
      [3] => 1 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 0 
      [9] => 0 
     ) 

    [3] => Array 
     (
      [0] => 1 
      [1] => 0 
      [2] => 0 
      [3] => 1 
      [4] => 0 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
      [9] => 0 
     ) 

    [4] => Array 
     (
      [0] => 1 
      [1] => 1 
      [2] => 1 
      [3] => 1 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 1 
      [9] => 0 
     ) 

    [5] => Array 
     (
      [0] => 1 
      [1] => 0 
      [2] => 0 
      [3] => 1 
      [4] => 0 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
      [9] => 0 
     ) 

    [6] => Array 
     (
      [0] => 1 
      [1] => 0 
      [2] => 0 
      [3] => 1 
      [4] => 0 
      [5] => 1 
      [6] => 0 
      [7] => 0 
      [8] => 1 
      [9] => 0 
     ) 

    [7] => Array 
     (
      [0] => 1 
      [1] => 0 
      [2] => 0 
      [3] => 1 
      [4] => 0 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
      [9] => 0 
     ) 

    [8] => Array 
     (
      [0] => 0 
      [1] => 0 
      [2] => 0 
      [3] => 0 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 0 
      [9] => 0 
     ) 

    [9] => Array 
     (
      [0] => 0 
      [1] => 0 
      [2] => 0 
      [3] => 0 
      [4] => 0 
      [5] => 0 
      [6] => 0 
      [7] => 0 
      [8] => 0 
      [9] => 0 
     ) 

) 

それは1(1)を与える結果

echo $hoppa[1][1]; 

として0(ゼロ)を与えます結果として

echo $hoppa[2][0]; 

結果に0(ゼロ)の値を表示したくありません。私は結果としてPHPスクリプトを1に戻したい。どの機能を使うべきですか?または私にサンプルを与えることができますか?

+0

foreach($hoppa as $k => $v) { $hoppa[$k] = array_filter($v); } 

これがその結果。私は正しいですか? –

+0

@Babak Naffas、はい。それは私が欲しいものです。私はprint_r($ hoppa)を使いたい。 1つの値しか得られません。 – Taffarel

+0

ドキュメントによると、あなたは間違った機能を見ている。 http://php.net/manual/en/function.print-r.php –

答えて

2

使用:値は、あなたの質問の私の理解では0である場合は、出力は何にあなたのコードをしたくない

php > print_r($hoppa); 
Array 
(
    [0] => Array 
     (
     ) 

    [1] => Array 
     (
     ) 

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

    [3] => Array 
     (
      [0] => 1 
      [3] => 1 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
     ) 

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

    [5] => Array 
     (
      [0] => 1 
      [3] => 1 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
     ) 

    [6] => Array 
     (
      [0] => 1 
      [3] => 1 
      [5] => 1 
      [8] => 1 
     ) 

    [7] => Array 
     (
      [0] => 1 
      [3] => 1 
      [5] => 1 
      [6] => 1 
      [7] => 1 
      [8] => 1 
     ) 

    [8] => Array 
     (
     ) 

    [9] => Array 
     (
     ) 

) 
+0

ありがとう、それは動作します。 – Taffarel