Php foreach结果在同一行上
我有以下代码:Php foreach结果在同一行上,php,html,css,Php,Html,Css,我有以下代码: 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) {
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 /
谢谢 A是块级元素。改用像
这样的内联元素
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/>";
}
}
?>
foreach($ck作为$k){
如果(substr($k,0,1)='')
{//跳过以“\”开头的键
继续;
}
$cv=get_post_custom_值($k,$post_id);//数组
foreach($cv为$c){
如果(空($c))
{//跳过空值
继续;
}
$format_c=$c;
echo“$k:$format_c/
”;
}
}
?>
另外,我不认为print\u r()
做你认为它做的事情。或用于输出文本。foreach($k为ck){
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>';
}
如果(substr($k,0,1)='')
{//跳过以“\”开头的键
继续;
}
$cv=get_post_custom_值($k,$post_id);//数组
回声';
foreach($cv为$c){
如果(空($c))
{//跳过空值
继续;
}
$format_c=$c;
打印($k.:'.$format_c./);
}回声';
}
?>有什么区别?不要将其放入
更改DIV的CSS,使其显示为inline
@thecodese格式混乱,第一组3个结果之间应该有换行符。
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>';
}