今このようなPHPがあるのですが、ほぼ同じコードで一部を変えて、function sitsumon(){}
の関数にバージョンを増やしたいです。
$fluits1
と$fluits2
に代入される内容だけが違うバージョンです。
php
1function sitsumon(){ 2 3 function example(){ 4 $xxx = 'xxx'; 5 $yyy = 'yyy'; 6 if($xxx == $yyy){ 7 return false; 8 } 9 } 10 11 $fluits1 = get_post_meta($post->ID , '形' ,true); 12 $fluits2 = get_post_meta($post->ID , '色' ,true); 13 14 $itemArr = example($fluits1, $fluits2); 15 16 foreach ($itemArr as $product => $price) { 17 echo "<p>{$product}</p><p>{$price}</p>"; 18 } 19 20}
代入される内容の具体的な違いは、
$fluits1 = get_post_meta($post->ID , '形' ,true);
$fluits2 = get_post_meta($post->ID , '色' ,true);
の部分だけが
$fluits1 = get_the_terms( $post->ID, '味' );
$fluits2 = get_the_terms( $post->ID, '趣' );
となるようなバージョンを作りたいと思っています。
現状は<?php sitsumon(); ?>
とすれば<p>{$product}</p><p>{$price}</p>
がecho
されるわけですけれど、
質問は<?php sitsumon(meta); ?>
と<?php sitsumon(terms); ?>
のようなバージョンを作りたいイメージです。
そのようなケースでは、上のPHPはどう書き直せばいいのかご教示頂ければ幸いです。
よろしくお願い致します。
回答2件
あなたの回答
tips
プレビュー