douruobokui58233
douruobokui58233
2014-02-01 09:39

将DB中的值放入数组中

  • if-statement
  • database
  • php
  • arrays
已采纳

I want to put my DB values into array

 $lic=array();
if ($lic[0] == 1)
{
    echo "Pirma lic ir";
}
elseif ($lic[0] == 0)
{
    echo "Pirma lic nav";
}
else
{

}


if ($lic[1] == 1)
{
    echo "Otra lic ir";
}
elseif ($lic[1] == 0)
{
    echo "Otra lic nav";
}
else
{

}

$lic I get from my DB

$lic = mysql_real_escape_string($row['lic']); // licences

So from

echo " ".$lic." "; <<<<<----- from this 

From this I get 1,1,1,1,1 - all of them can be 0 or 1.

I want to put them into array so I can define what's first,second,third I want them to be in array() <- Inside this How do I get it there?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douwu7563 douwu7563 7年前

    ok so u mean you want to split the string from "1, 1, 1, 0 ,1" to array??

    so to split you can use ..

    // if you $lic is like below 
    $lic  = "1, 1, 0, 1, 0, 1, 0, 0";
    
    $arr = explode(", ", $lic);
    
    echo $arr[0]; // 1
    echo $arr[1]; // 1
    echo $arr[2]; // 0
    
    点赞 评论 复制链接分享