Eugene Posted December 27, 2006 Share Posted December 27, 2006 [code=php:0]<?PHP$somearray = array('one' => '{$somevar}'); returns {$somevar}$somearray = array('one' => $somevar); returns parse error, unexpected T_VARIABLE$somearray = array('one' => '$somevar'); returns $somevar?>[/code]A little help would be great on why that isn't working. ;D Link to comment https://forums.phpfreaks.com/topic/31959-php-arrays/ Share on other sites More sharing options...
obsidian Posted December 27, 2006 Share Posted December 27, 2006 Hmm... is $somevar set? Your second attempt should be right, but I have to wonder if you may be missing the semicolon in the line above it, though:[code]<?php// Either of these should work:$somearray = array('one' => $somevar);$somearray = array('one' => "$somevar");?>[/code]Notice that with [b]double quotes[/b], your variable will be interpreted. Single quotes return the literal characters contained within them. Link to comment https://forums.phpfreaks.com/topic/31959-php-arrays/#findComment-148291 Share on other sites More sharing options...
Eugene Posted December 27, 2006 Author Share Posted December 27, 2006 Niether of them work. Link to comment https://forums.phpfreaks.com/topic/31959-php-arrays/#findComment-148296 Share on other sites More sharing options...
alpine Posted December 27, 2006 Share Posted December 27, 2006 [code]<?php$somevar = "this is var";$somearray = array('one' => $somevar);print_r($somearray); // outputs: Array ( [one] => this is var )$somearray = array('one' => "$somevar");print_r($somearray); // outputs: Array ( [one] => this is var )?>[/code] Link to comment https://forums.phpfreaks.com/topic/31959-php-arrays/#findComment-148307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.