EchoFool Posted February 20, 2012 Share Posted February 20, 2012 Hey I have a script that builds an array but for some reason there is a loose integer in the variable which is confusing me and i think its the cause of my syntax errors in javascript. But i got no idea where it is coming from =/ Here is the function i use: <?php function img($id) { $img = array(); $img['tiles'] = $this->db->getAll("SELECT DISTINCT t.id, CONCAT('data/tiles/',filename) AS f FROM `map_tiles` AS mt INNER JOIN `tiles` AS t ON (mt.tile=t.id) WHERE mt.map_id={$this->db->qstr($id)}"); echo print_r($img); die; //exit(json_encode($img)); // turned off for testing ?> The echo returns this: Array ( [tiles] => Array ( [0] => Array ( [id] => 10 [f] => data/tiles/floor.png ) ) ) 1 <----- why does this appear? And could this cause a syntax error if sent back for JS processing? As you can see there is 1 showing at the end but i don't see why =/ Any ideas if thats suppose to happen ? Quote Link to comment https://forums.phpfreaks.com/topic/257416-unknown-reason-for-a-value-in-an-array/ Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2012 Share Posted February 20, 2012 Because you're using echo with print_r(). Remove the echo. Quote Link to comment https://forums.phpfreaks.com/topic/257416-unknown-reason-for-a-value-in-an-array/#findComment-1319370 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 Ah i see, thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/257416-unknown-reason-for-a-value-in-an-array/#findComment-1319372 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2012 Share Posted February 20, 2012 print_r() prints the output, and on success it returns TRUE, which echo echoes as a 1. Quote Link to comment https://forums.phpfreaks.com/topic/257416-unknown-reason-for-a-value-in-an-array/#findComment-1319373 Share on other sites More sharing options...
EchoFool Posted February 20, 2012 Author Share Posted February 20, 2012 Understood - thanks for the explaination Quote Link to comment https://forums.phpfreaks.com/topic/257416-unknown-reason-for-a-value-in-an-array/#findComment-1319375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.