0
<!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>

I am sending information via javascript using php but $kid ,$mother and $father are in array format . So its showing me an error.

Notice: Array to string conversion in C:\xampp\htdocs\sbs\sbs\html\meta.php on line 19
Array' ,

3
  • It is hard to tell why as we cannot see what you have actually in those variables. Try var_dump on them and see what format they are. Commented Oct 1, 2013 at 13:24
  • Shouldn't you really dump or echo those variables ? Commented Oct 1, 2013 at 13:24
  • Also, it would be easier to create an array in PHP, and just json_encode it ! Commented Oct 1, 2013 at 13:25

1 Answer 1

5

<?= converts the variable to a string and outputs it. Implicitly converting arrays to strings results in a notice (not an error).

I advise you to use 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); ?>;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.