i'm iterating through and associative array like so:
for (entry in $data[array]) {
// do some stuff
}
i need to assign a value based on the NAME of a key, like so (pseudo-code):
for (entry in $data[array]) {
// do some stuff
if ($data[array][entry]['type'].name = 'thingy') {
// so some other stuff
} else {
// keep doing some stuff
}
}
thing is, i can't get the zero'th element to cough up its key name such that it can be used as i've typed it (i'm aware it doesn't work...) the array itself looks like this:
$data
(
[success] => 1
[findings] =>
(
[0] =>
(
[type] => thingy
[name] => yo-yo
[age] => 1960
)
[1] =>
(
[type] => doohickey
[name] => clothespin
[age] => 1940
)
)
)
so...essentially what i'm needing to do is do something different if the KEY is a 'type'. basically for every key of 'type', make text red, for example.
what am i missing to make it work? :P i hope i'm making myself clear...
WR!
arraywill be a string variable, with its value being'success'or'findings'? And, what do you mean by "the KEY" or "the NAME of a key"? It seems like the "name" or "key" of$data[array][entry]['type']is simply'type'. No? I think that real code, with actual JavaScript syntax, would probably be more clear.thenin JS. Next, anifis a conditional, not a loop. Sloppiness leads you straight into bugland. Then, you're assigning in a conditional - likely a bug. Alsoageas 1940 and 1960, that's probably year of birth. - What are you trying to say anyway?.namei tacked on the end to indicate i was looking for the key's name there. for the tarde-mente: `if (the keys name is 'thingy) {do other stuff} else {do stuff}.arrayas a variable-name to refer to a key, reinforcing this notion; and (4) the fact that your whole question was asking how to do something -- pardon me -- something incredibly obvious, so I assumed that I must be misunderstanding you.