Neither if nor else will run
I don't know what the problem is.
This is the code that is the problem:
$thisvb = (int) $key2;
if ($thisvb == ($lastvb + 1)) { //This don't work
echo '<li>';
} else { echo '<li value="' . $key2 . '">';}
$last = (int) $key2;
Below is the full code.
<?php
$voiceboxes = array(
'141133' => array(
'1' => array(
'Title' => 'Title2',
'Link' => 'http://...',
),
'2' => array(
'Title' => 'Title3',
'Link' => 'http://...',
),
'3' => array(
'Title' => 'Title4',
'Link' => 'http://...',
)
)
);
$last = 0;
//$this = 0;
echo "<ol>\n";
foreach ($voiceboxes as $key => $value) {
$lastvb = 0;
$thisvb = 0;
//$voiceboxes[$key]['title']
echo "<ol>\n";
foreach ($value as $key2 => $value2) {
$thisvb = (int) $key2;
if ($thisvb == ($lastvb + 1)) { //This don't work
echo '<li>';
} else { echo '<li value="' . $key开发者_如何转开发2 . '">';}
$last = (int) $key2;
echo $voiceboxes[$key][$key2]['Title'] . "<br/>" . $voiceboxes[$key][$key2]['Link'] . '</li>' . "\n";
}
}
echo "</ol>\n";
echo '</ol>';
?>
This is what I get
<ol>
<ol>
<li>Title2<br/>http://...</li>
Title3<br/>http://...</li> <!-- this ain't right, it should start with <li> -->
Title4<br/>http://...</li> <!-- same here -->
</ol>
</ol>
I can't figure it out, does anyone know?
} else { '<li value="' . $key2 . '">';}
//--------^
You missed an echo
.
You forgot echo
inside the else statement.
You're not echoing the else statement; it is just being uttered, it is not being output.
You're missing an echo
in the else clause.
You're missing an 'echo' in your else statement. Try adding that in and see what output you get.
You say you've updated the code and its still giving you an error, but its still missing an echo
} else { '<li value="' . $key2 . '">';}
^
精彩评论