2017-01-09 14 views
1

機能1:foreachループ内から配列をマージするにはどうすればよいですか?

function print_vcard($card, $hide){ 

    $names = array('N', 'FN', 'TITLE', 'TEL', 'EMAIL', 'URL', 'ADR', 'NOTE'); 

    $row = 0; 

    foreach ($names as $name) { 
     if (in_array_case($name, $hide)) { 
      continue; 
     } 
     $properties = $card->getProperties($name); 
     if ($properties) { 
      foreach ($properties as $property) { 
       $show = true; 
       $types = $property->params['TYPE']; 
       if ($types) { 
        foreach ($types as $type) { 
         if (in_array_case($type, $hide)) { 
          $show = false; 
          break; 
         } 
        } 
       } 
       if ($show) { 
        $class = ($row++ % 2 == 0) ? "property-even" : "property-odd";     
        print_vcard_property($property, $class, $hide); 
       } 
      } 
     } 
    } 
} 

機能2:

function print_vcard_property($property, $class, $hide){ 
     $items = array(); 
     $name = $property->name; 
     $value = $property->value; 
     $types = $property->params['TYPE']; 
     switch ($name) { 
      case 'N': 
       $name = $property->getComponents(); 
       print_r(array_filter($name)); 
       break; 
       case 'TEL': 
       $phone = $property->getComponents(); 
       print_r(array_filter($phone)); 
       break; 
       case 'ADR': 
       $adr = $property->getComponents(); 
       print_r(array_filter($adr)); 
       break; 
      default: 
       $components = $property->getComponents(); 
       $lines = array(); 
       foreach ($components as $component) { 
        if ($component) { 
         $lines[] = $component; 
        } 
       } 
       $html = join("\n", $lines); 
       break; 
     } 
     echo "<br><br>"; 
    } 

私の出力:

print_r(array_merge($name,$phone,$adr)); 

:私は1つのアレイになりまし出力をマージしたい

Array ([0] => Miller [1] => Sam) 

Array ([0] => 434234234) 

Array ([2] => Sunstreet 3211 [3] => Miami [5] => 1234) 

Warning: array_merge(): Argument #2 is not an array in mypage.php on line 259 
+0

機能1' print_vcard_property($プロパティ、$クラス、$皮)の内側に交換したときにそれが働いていたが、私はエラーメッセージが表示されます – Jarla

+0

このコメントを回答として追加して受け入れてください。あなたの質問はもう返信されないように見えます。 – Veve

答えて

0

作業溶液:; `関数2の内容に

function print_vcard($card, $hide){ 

    $names = array('N', 'FN', 'TITLE', 'TEL', 'EMAIL', 'URL', 'ADR', 'NOTE'); 

    $row = 0; 

    foreach ($names as $name) { 
     if (in_array_case($name, $hide)) { 
      continue; 
     } 
     $properties = $card->getProperties($name); 
     if ($properties) { 
      foreach ($properties as $property) { 
       $show = true; 
       $types = $property->params['TYPE']; 
       if ($types) { 
        foreach ($types as $type) { 
         if (in_array_case($type, $hide)) { 
          $show = false; 
          break; 
         } 
        } 
       } 
       if ($show) { 
        $class = ($row++ % 2 == 0) ? "property-even" : "property-odd";     
        $items = array(); 
        $name = $property->name; 
        $value = $property->value; 
        $types = $property->params['TYPE']; 
        switch ($name) { 
         case 'N': 
          $name = $property->getComponents(); 
          print_r(array_filter($name)); 
          break; 
          case 'TEL': 
          $phone = $property->getComponents(); 
          print_r(array_filter($phone)); 
          break; 
          case 'ADR': 
          $adr = $property->getComponents(); 
          print_r(array_filter($adr)); 
          break; 
          default: 
          $components = $property->getComponents(); 
          $lines = array(); 
          foreach ($components as $component) { 
          if ($component) { 
           $lines[] = $component; 
          } 
         } 
         $html = join("\n", $lines); 
         break; 
        } 
        echo "<br><br>"; 
       } 
      } 
     } 
    print_r(array_merge($name,$phone,$adr)); 
    } 
} 
関連する問題