Results 1 to 6 of 6
November 8th, 2010, 02:16 PM #1PHP & Arrays
Alright, I'm stuck. I've tried hundreds of combinations but can't seem to figure this out. I'm not even sure if this is possible. I tried searching for an answer but given the common terms involved, it made it difficult at best.
Basically, I have an array that I'm using on a script. I want to add to the array an element that has words as well as today's date. Here's what I have:
$temp_array = array(
'It was added on '.$today,
'I went on '.$today
November 8th, 2010, 03:38 PM #2PHP Code:
$temp_array = array(
'a'=>"It was added on $today",
'b'=>"I went on $today"
echo $temp_array['a'].'<br />';
November 8th, 2010, 04:21 PM #3
John. Once again. Thank you. As someone who has looked at your past posts, you have definitely contributed some great stuff over the years.
Hmm. I see that works in that situation. Now, how can I get it to do this? Basically, I'm setting up an array of around 100 different little phrases for when a user enters some info on my site. I'm then picking a random element from the array using this function:
$reply = $temp_array[array_rand($temp_array)];
I tried adding  after $temp_array but that didn't work. More plugging away I guess!
November 8th, 2010, 05:01 PM #4
Ok. I decided to choose the phrase this way. I just randomly pick a number. So if I have 10 comments, I have it randomly pick a number between 1 and 10. Instead of using 'a' 'b', I'm using numbers. Seems to work fine in the example above. I add the code to my script and it works fine. However, I when I put a little function for this, for whatever reason, it doesn't seem to work? Even if I just try to echo the results. I'll keep plugging away and report back!
Last edited by gcarson; November 8th, 2010 at 05:05 PM.
November 8th, 2010, 05:14 PM #5
Edit.. nevermind. I'm pretty much an idiot. The $today variable is defined outside of the function. So when I tried adding it in the function, it came up blank. I couldn't for the life of me figure out why it worked outside the function but not inside. So it worked the first way I had but since I never defined the date inside the function, it was coming up blank.
Thanks again John for your help!
Last edited by gcarson; November 8th, 2010 at 05:17 PM.
November 8th, 2010, 05:20 PM #6
Glad you got it.
By Steve Williams in forum PopShopsReplies: 52Last Post: March 21st, 2008, 09:31 AM
By ELO in forum GoldenCANReplies: 6Last Post: September 7th, 2006, 07:24 PM
By Rhia7 in forum Programming / Datafeeds / ToolsReplies: 10Last Post: April 15th, 2006, 02:25 AM
By SpaceBandit in forum Programming / Datafeeds / ToolsReplies: 11Last Post: January 7th, 2002, 04:52 PM