Darn I am missing one simple step with this PHP array please help
Posted by lexington, 02-10-2011, 09:48 AM Hello, I have been up all night so my brain must be fried since I cannot figure this simple thing out. I am trying to assign values from an array to a variable. I can echo the $key and $val just fine, but when I try to assign them to a variable, it doesn't work. I *think* I have to use $config[] or $config = array() before it starts, but neither are working so I am doing something wrong. Here is the code example: That works just fine, when you echo the data it shows the key and it's value. However I am trying to make a variable use those values, like: So that each $config[ name ] equals $row[ value ] and for some reason it doesn't work. I assume I need to add something first with $config and $row to make the values assign to those variables. They just appear empty on the page. Please help. Last edited by lexington; 02-10-2011 at 09:58 AM.
Posted by GGWH-James, 02-10-2011, 09:57 AM
Posted by Squidix - SamBarrow, 02-10-2011, 09:58 AM You're trying to pull something out of $row but I don't see you ever creating it.
Posted by lexington, 02-10-2011, 10:04 AM Thanks GGWH-James I did that but the $config[$key] value is still empty. If you echo it on your end does it show? Thanks samb0057, yes you are right I do not know the $row, the $val works now but $config[$key] is still empty.
Posted by GGWH-James, 02-10-2011, 10:06 AM outputs:
Posted by Squidix - SamBarrow, 02-10-2011, 10:08 AM James' code looks like it should work. Try this:
Posted by lexington, 02-10-2011, 10:09 AM Thanks again, it works. I thoguht I could echo each value within the while loop though, like No worries though, all is fine
Posted by lexington, 02-10-2011, 10:11 AM Oops, nevermind it works. Last edited by lexington; 02-10-2011 at 10:16 AM.
Posted by lexington, 02-10-2011, 10:16 AM ROFL, oops everything is fine. For some odd reason that array name was not in my original array. Weird I could have sworn I added it, all works now thanks again