<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script src="./js/jquery.js"></script>
<script src="./js/laddubox.js"></script>
<script src="./js/pop.js"></script>
<script src="./js/jquery.js"></script>
<script type="text/javascript">
var sbs = {
'url' : '<?="./gearedup-pics/"?>',
'logged' : '<?=$notregister?>',
'userid' : '<?= $id ?>',
'father' : '<?= $father ?>' ,
'mother' : '<?= $mother ?>',
'kid' : "<?= $kid ?>"
};
</script>
<title><?=$title?></title>
</head>
我使用php通过javascript发送信息,但 $ kid,$ mother和$ father 采用数组格式。所以它给我一个错误。
注意: 19 C:\ xampp \ htdocs \ sbs \ sbs \ html \ meta.php 中的数组转换为字符串 数组',
答案 0 :(得分:5)
<?=
将变量转换为字符串并输出。将数组隐式转换为字符串会产生通知(而不是错误)。
我建议你使用json_encode()
:
<?php
$data = array(
'url' => './gearedup-pics/',
'logged' => $notregister,
'userid' => $id,
'father' => $father,
'mother' => $mother,
'kid' => $kid
);
?>
var sbs = <?php echo json_encode($data); ?>;