It looks like you're using an Ad Blocker.

Please white-list or disable in your ad-blocking tool.

Thank you.


Some features of ATS will be disabled while you continue to use an ad-blocker.


PHP Driving me nuts!!

page: 1

log in


posted on Jul, 4 2009 @ 01:36 AM
Hi All,

I'm trying to read through an array of strings, and spit out the string relevant to the array index....

for example

a: Active, Abstanence, Airy
b: Behave, Beautiful, Banana
c: Carrot, Caring
d: Dangerous, Dabble, Dooby

So if someone put in "babad" In the field, it would output

b: Behave
a: Active
b: Beautiful (because its the second B in the array)
a: Abstanence (because its the second A in the array)
d: Dangerous

Any Idea what i need to do in the processing index page. I've tried foreach, while, etc... but i can't get it right.

Thanks in advance...

posted on Jul, 4 2009 @ 11:34 AM
reply to post by Im a Marty

I don't know PHP, but I think you could use an index for each array, and use it to get the right word, increasing it after that.

Or is the problem parsing the "babad"?

posted on Jul, 4 2009 @ 01:12 PM
Thats the general idea of it yes, but I don't know the code on how to do it which is the problem.

I got it counting how many times each letter appears, yet I can't pull the 'second' meaning for the second time the letter appears from the array....

Thanks anyway

posted on Jul, 4 2009 @ 06:46 PM
im not too sure what you're trying to do but did you trying using multidemensional associative arrays? like..

"b"=>array("Behave", "Beautiful", "Banana"),
"c"=>array("Carrot", "Caring"),
"d"=>array("Dangerous", "Dabble", "Dooby")

posted on Jul, 4 2009 @ 07:22 PM
reply to post by radioactive_liquid

Thats exactly how I have it....

Then in the processing page I have this..

foreach ($chars as $value) [
if ($chars[$a] == 'A')
print ($namearray['A'][$a]);
if ($chars[$b] == 'B')
print ($namearray['B'][$b]);

Each letter going to Z. Now $namearray is '$example'. and $chars is the str_split of $input.

So if i put in ABB, it should print off first meaning of A, then first meaning of B, then SECOND meaning of B. For some reason this isn' working with the code above...

Thanks again!

[edit on 4/7/2009 by Im a Marty]

posted on Jul, 4 2009 @ 08:32 PM
Ok i got it working all, thanks to everyone for helping out

Thanks again

top topics

log in