simple array issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

simple array issues

Post by Charles256 »

Code: Select all

$access_name = $guid_arr[$guid_id];
where guid_arr is an array with one of the entries
'{C458257A-E596-4B9F-8AAC-873190CDD87A}' => '3daypass'

and guid_id is
{C458257A-E596-4B9F-8AAC-873190CDD87A}

if i go $guid_arr['that string'] it works fine but if i do it as you see at the top it doesn't work.why?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you 100% sure $guid_id is that string? var_dump() it. I'd guess it has whitespace in there somewhere, or a null character.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Cannot reproduce it either

Code: Select all

<?php
$guid_arr = array(
		'{C458257A-E596-4B9F-8AAC-873190CDD87A}'=>'3daypass',
		'{C458257A-E596-4B9F-8AAC-873190CDD87B}'=>'7daypass',
		'{C458257A-E596-4B9F-8AAC-873190CDD87C}'=>'14daypass',
		'{C458257A-E596-4B9F-8AAC-873190CDD87D}'=>'21daypass'
	);


$guid_id = '{C458257A-E596-4B9F-8AAC-873190CDD87A}';
echo $access_name = $guid_arr[$guid_id];
?>
works fine.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

yep.there was a bit of white space.slapping trim on it.i'll let ya know.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

yep.slap trim on it and good to go.
Post Reply