4xjbh Posted July 11, 2013 Share Posted July 11, 2013 (edited) My php code is currently separated from my html, at least as much as possible without using a framework or template system. I am echoing out $result['title'] in my html, is there an easy way to convert it to a variable so I can use $title instead? current html: <?php foreach ($results as $row): ?> <?php echo $row['title'] ?> <?php echo $row['description'] ?> <?php endforeach; ?> php: $results=$conn->query($sql); Edited July 11, 2013 by 4xjbh Quote Link to comment https://forums.phpfreaks.com/topic/280055-array-to-variable/ Share on other sites More sharing options...
fastsol Posted July 11, 2013 Share Posted July 11, 2013 (edited) $title = $row['title']; Edited July 11, 2013 by fastsol Quote Link to comment https://forums.phpfreaks.com/topic/280055-array-to-variable/#findComment-1440261 Share on other sites More sharing options...
web_craftsman Posted July 11, 2013 Share Posted July 11, 2013 You may consider using http://php.net/manual/en/function.list.php Quote Link to comment https://forums.phpfreaks.com/topic/280055-array-to-variable/#findComment-1440268 Share on other sites More sharing options...
AbraCadaver Posted July 11, 2013 Share Posted July 11, 2013 I don't use it anymore and it may be frowned upon, especially with un-trusted data, but look at extract(). Quote Link to comment https://forums.phpfreaks.com/topic/280055-array-to-variable/#findComment-1440314 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.