makamo66 Posted May 22, 2010 Share Posted May 22, 2010 I can write this and get the right results: if ( $_SESSION['addId'] == 'add[4]' ) $productId = 1; if ( $_SESSION['addId'] == 'add[5]' ) $productId = 2; if ( $_SESSION['addId'] == 'add[6]' ) $productId = 3; But if I try to streamline it by writing it this way, it doesn't work: if ( $_SESSION['addId'] == 'add[$i]' ) $productId = $i; I think the two methods should be equivalent so why doesn't the second way work? Quote Link to comment https://forums.phpfreaks.com/topic/202552-writing-a-simple-statement-with-an-index/ Share on other sites More sharing options...
trq Posted May 22, 2010 Share Posted May 22, 2010 Variables are not interpolated within single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/202552-writing-a-simple-statement-with-an-index/#findComment-1061841 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.