thunder708 Posted February 8, 2010 Share Posted February 8, 2010 Hi i have this code that turns hex value to RGB value but only problem is i can only find out how to print the array, i want to be able to use the array contents and im failing to do so here is the code <? function hex2rgb($hex){ $rgb = array(); $rgb['r'] = hexdec(substr($hex, 0, 2)); $rgb['g'] = hexdec(substr($hex, 2, 2)); $rgb['b'] = hexdec(substr($hex, 4, 2)); return $rgb; } print_r(hex2rgb('ffffff')); ?> i have tried using: echo "$rgb['r']; and respectively for g and b but i cant get an output, any suggestions will be most helpful =D thanks Quote Link to comment https://forums.phpfreaks.com/topic/191338-php-array-problem/ Share on other sites More sharing options...
PravinS Posted February 8, 2010 Share Posted February 8, 2010 Try this <?php function hex2rgb($hex){ $rgb = array(); $rgb['r'] = hexdec(substr($hex, 0, 2)); $rgb['g'] = hexdec(substr($hex, 2, 2)); $rgb['b'] = hexdec(substr($hex, 4, 2)); return $rgb; } print_r(hex2rgb('ffffff')); $colors = hex2rgb('ffffff'); echo "<br>".$colors['r']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/191338-php-array-problem/#findComment-1008792 Share on other sites More sharing options...
jskywalker Posted February 8, 2010 Share Posted February 8, 2010 $a=hex2rgb('eeeeee'); print $a['r']; Quote Link to comment https://forums.phpfreaks.com/topic/191338-php-array-problem/#findComment-1008795 Share on other sites More sharing options...
thunder708 Posted February 8, 2010 Author Share Posted February 8, 2010 Thank yoiu both or such a quick reply, both of your ways work, i dont know why i didnt see how simple that could have been, i over think things at times lol. Thank you much =D Quote Link to comment https://forums.phpfreaks.com/topic/191338-php-array-problem/#findComment-1008798 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.