JamesThePanda Posted January 13, 2010 Share Posted January 13, 2010 ok I have this function called the_ID(); I want to set it as a variable So i did the following $id = the_id(); And to test it I wanted to echo $id so this was the simple piece of code I wrote <?php $id = the_ID(); echo $id; ?> But nothing is being echoed what am doing wrong ? Thanks James Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2010 Share Posted January 13, 2010 Echoing a FALSE value generally does not echo anything. You can try var_dump($id); to determine exactly what is in the variable. Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/#findComment-994204 Share on other sites More sharing options...
PHP Monkeh Posted January 13, 2010 Share Posted January 13, 2010 Well we'd need to see the code for your function to correct it, but I'd guess that it doesn't return any values. Example: <?php function the_ID() { return 2; } $id = the_ID(); echo $id; // 2 is echo'd ?> Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/#findComment-994205 Share on other sites More sharing options...
JamesThePanda Posted January 13, 2010 Author Share Posted January 13, 2010 wellits ment to echo a page number If i do <?php echo the_ID(); ?> That echos the page number but I want to take the page number and do thing with it so I want to be able to have it as a variable. Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/#findComment-994206 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2010 Share Posted January 13, 2010 If you can use echo the_ID(); and it works, then you can assign that to a variable and use that variable. If that variable then does not have the expected value in it, your code has done something to that variable between the point where it was assigned a value and where you are using it. You will need to post your actual code if you want help with why it is not working. Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/#findComment-994208 Share on other sites More sharing options...
sasa Posted January 13, 2010 Share Posted January 13, 2010 in your function change 'echo' to 'return' Quote Link to comment https://forums.phpfreaks.com/topic/188329-varibale-problem/#findComment-994377 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.