players将为空或以逗号分隔的列表(或单个值)。检查它是否为空的最简单方法是什么?我假设我可以将$gameresult数组放入$gamerow? 在这种情况下,如果它是空的,跳过爆炸可能会更有效$playerlist,但为了论证,我将如何检查数组是否也为空?
players
$gameresult
$gamerow
$playerlist
$gamerow = mysql_fetch_array($gameresult); $playerlist = explode(",", $gamerow['players']);
如果您只需要检查数组中是否有任何元素
if (empty($playerlist)) { // list is empty. }
如果您需要在检查之前清除空值(通常是为了防止出现explode奇怪的字符串):
explode
foreach ($playerlist as $key => $value) { if (empty($value)) { unset($playerlist[$key]); } } if (empty($playerlist)) { //empty array }