[英]foreach array displaying result
I have been looking at this code etc for so long that I am now confusing myself - not good 我一直在看这段代码等了很久,以至于现在让自己感到困惑-不好
I have foreach of 我有
foreach($sort_order as $sort)
{
echo '<pre>';
var_dump($sort['sorder']);
echo '</pre>';
}
That gives me a result of: 这给了我以下结果:
string(2) "20"
string(2) "10"
How can I return this so I can do value="<?php echo $someValue; ?>"
如何返回此value="<?php echo $someValue; ?>"
以便可以执行value="<?php echo $someValue; ?>"
Assuming that 'sorder' is a key in your array I would try the following: 假设“顺序”是数组中的键,我将尝试以下操作:
foreach($sort_order as $key => $sort) {
echo '<pre>';
if($key == "sorder") {
echo $sort[$key];
}
echo '</pre>';
}
It looks like you're only displaying they key. 看来您只在显示它们的关键。 I'm assuming your array is of type associative. 我假设您的数组是关联类型的。
To traverse associative arrays in PHP, follow this: 要遍历PHP中的关联数组,请遵循以下步骤:
foreach($array as $key => $value)
{
echo "[" . $key . "]" . " = " . $value . "<br />;
}
I'm not sure what are you trying to do but... 我不确定您要做什么,但是...
<?php
$val = array();
foreach($sort_order as $sort) {
$val[] = $sort['sorder'];
}
?>
<p>value = <?php echo $val[0]; ?></p>
<p>value = <?php echo $val[1]; ?></p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.