erme Posted October 17, 2011 Share Posted October 17, 2011 I have just re-installed Xampp and suddenly my sites are now displaying lots of: Notice: Use of undefined constant name - assumed 'name' in ... Notice: Use of undefined constant price - assumed 'price' in ... this is an example of the line its refering too: $defineProducts[1001] = array(name=>'This is a product', price=>123); Link to comment https://forums.phpfreaks.com/topic/249273-notice-use-of-undefined-constant-variable-assumed-variable-in/ Share on other sites More sharing options...
Pikachu2000 Posted October 17, 2011 Share Posted October 17, 2011 String values need to be quoted. Link to comment https://forums.phpfreaks.com/topic/249273-notice-use-of-undefined-constant-variable-assumed-variable-in/#findComment-1280013 Share on other sites More sharing options...
erme Posted October 17, 2011 Author Share Posted October 17, 2011 I have tried $defineProducts[1001] = array("name=>Loom Style Conservatory Suite in White Cane, price=>375"); and $defineProducts[1001] = array("name=>Loom Style Conservatory Suite in White Cane", "price=>375"); and $defineProducts[1001] = array(name=>"Loom Style Conservatory Suite in White Cane", price=>"375"); but doesn't work Link to comment https://forums.phpfreaks.com/topic/249273-notice-use-of-undefined-constant-variable-assumed-variable-in/#findComment-1280015 Share on other sites More sharing options...
Pikachu2000 Posted October 17, 2011 Share Posted October 17, 2011 You don't enclose both the key and value in one set of quotes. Each gets its own set. $array = array( 'key1' => 'value1', 'key2' => 'value2' ); Link to comment https://forums.phpfreaks.com/topic/249273-notice-use-of-undefined-constant-variable-assumed-variable-in/#findComment-1280022 Share on other sites More sharing options...
ManiacDan Posted October 17, 2011 Share Posted October 17, 2011 The manual section on Arrays will tell you everything you need to know about proper array syntax. Also, you were developing without error-reporting turned on before. Always turn it on and leave it on, otherwise one day you'll realize every single line of array access is wrong. -Dan Link to comment https://forums.phpfreaks.com/topic/249273-notice-use-of-undefined-constant-variable-assumed-variable-in/#findComment-1280031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.