Home > Backend Development > PHP Tutorial > 请问:数组元素中的单引号

请问:数组元素中的单引号

WBOY
Release: 2016-06-13 10:06:09
Original
1137 people have browsed it

请教:数组元素中的单引号
如下代码:
function method(){
$str = "apply";
$str2 = "tony";
$sql = "select * from table where 1 =1";
$Carray = array(" and cad like '%".$str."%'"," and name like '%".$str2."%'");
//echo($Carray[0]);
for($i=0;$i   $sql.=$Carray[$i];
}
echo $sql;
}

这段代码是为了简便自己先写的,我想问的是为什么输不出$sql,也就是说输不出数组中的元素,当加上echo($Carray[0]);这一句的时候,是输不出东西的,是不是数组中的单引号出问题了?

------解决方案--------------------
没有问题啊。
输出:select * from table where 1 =1 and cad like '%apply%' and name like '%tony%'
------解决方案--------------------

PHP code
function method() {    $str = "apply";    $str2 = "tony";    $sql = "select * from table where 1 =1";    $Carray = array(" and cad like '%$str%'", " and name like '%$str2%'");    for ($i = 0; $i <font color="#e78608">------解决方案--------------------</font><br>单引号在双引号的字符串里就做单引号用<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template