[英]How to exclude a $row['weight'] from $cat_fields
Hi can you please help me to exclude a row from this peace of script: 嗨,您能帮我从此脚本中排除一行吗:
<?php
if($ad_fields!="") {
foreach ($ad_fields as $key => $value)
{
echo " <nobr><strong> ".$cat_fields[$key][0].": </strong>".
" ".$ad_fields[$key].$fld_dim[$key].$fld_dimd[$key].";<br /> </nobr> "; }}
?>
This script echo all rows, how can I achieve that script doesn't call out for example $row['weight'], or $row['weight'] & $row['height'] 此脚本回显所有行,如何实现该脚本不调用例如$ row ['weight']或$ row ['weight']和$ row ['height']
Thanks 谢谢
Your code-sample doesn't have a variable named $row
, so I'm assuming you're referring to $cat_fields
, $ad_fields
, $fld_dim
, or $fld_dimd
(which all appear to have the same keys). 您的代码示例没有名为
$row
的变量,因此我假设您引用的是$cat_fields
, $ad_fields
, $fld_dim
或$fld_dimd
(它们似乎都具有相同的键)。
You can check the value of the $key
in the foreach
-loop. 您可以在
foreach
-loop中检查$key
的值。 If it matches a value you don't want to display, use continue;
如果它与您不想显示的值匹配,请使用
continue;
to skip: 跳过:
foreach ($ad_fields as $key => $value) {
if (($key == 'weight') || ($key == 'height')) continue;
Alternatively, you can define an array of keys you want to skip and check with in_array()
: 另外,您可以使用
in_array()
定义要跳过和检查的键数组:
$skipKeys = array('weight', 'height');
foreach ($ad_fields as $key => $value) {
if (in_array($key, $skipKeys)) continue;
The second option may be better if your list of keys-to-skip grows rather long. 如果您要跳过的键列表相当长,则第二种选择可能更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.