foreach结果在同一行

时间:2017-03-20 21:32:17

标签: php html css

我有这个代码:     

onAttach

但结果是这样的:

    foreach ($ck as $k) {
         if (substr ($k, 0, 1) == '_')
         {   // skip keys starting with '_'
             continue;
         }
         $cv = get_post_custom_values($k, $post_id );  //Array

            foreach ($cv as $c) {
                if (empty ($c))
                {   // skip empty value
                    continue;
                }
                $format_c =  $c;

                print_r ('<div style="font-size: 14px;">'.$k .': '. $format_c . ' / </div>');

            }
    }

?>

如何更改代码:

something: result /
something: result /
something: result /

谢谢!

2 个答案:

答案 0 :(得分:1)

<div>是块级元素。请使用内联元素,例如<span>

    foreach ($ck as $k) {
         if (substr ($k, 0, 1) == '_')
         {   // skip keys starting with '_'
             continue;
         }
         $cv = get_post_custom_values($k, $post_id );  //Array

            foreach ($cv as $c) {
                if (empty ($c))
                {   // skip empty value
                    continue;
                }
                $format_c =  $c;

                echo "<span style='font-size: 14px;'>$k: $format_c / </span><br/>";

            }
    }

?>

另外,我认为print_r()不会做你认为它做的事情。 echoprint用于输出文字。

答案 1 :(得分:0)

foreach ($ck as $k) {
     if (substr ($k, 0, 1) == '_')
     {   // skip keys starting with '_'
         continue;
     }
     $cv = get_post_custom_values($k, $post_id );  //Array

      echo '<div style="display: inline; font-size: 14px;">';
        foreach ($cv as $c) {
            if (empty ($c))
            {   // skip empty value
                continue;
            }
            $format_c =  $c;

            print_r ($k .': '. $format_c . ' /);

        }echo '</div>';
}

&GT;