|
Posted by Michael Austin on 01/10/06 01:34
frizzle wrote:
> Hi there.
> I have this array:
>
> name => john, age => 45, profession => teacher
> name => hank, age => 22, profession => student
> name => mary, age => 36, profession => dancer
> etc.
> etc.
>
> It's going to be a big array.
>
> Now what i wonder, how can i do the following;
> while( $array['name'] == 22 )
> {
>
> do something.
>
> }
>
> I want to prevent the following:
> while( $array )
> {
>
> if( 'name' == 22 ){
>
> do something
>
> }
>
> }
>
> Because this would create a big loop everytime.
>
> Greetings Frizzle.
>
There are many ways to accomplish the end goal and there are many methods and
functions and constructs and tools to accomplish those goals.
I would use a database interface - like mysql. then select only the data you
want/need.
psuedo-code
$array = "select name,age,profession from mytable where name = 22"
foreach ($array as $x)
{ do something
}
or if you do not want to see information where the age = 22 then:
$array = "select name,age,profession from mytable where name <> 22"
foreach ($array as $x)
{ do something
}
you can even use case statements do to other things if
$ select name,case when age = 22 then age = 0 else age=age end,profession
from mytable where age < 25;
Now read and act on only the required data.
--
Michael Austin.
Everything is easier when the appropriate tool is used. Ever try removing a
tire with just a screwdriver??? (neither have I)
[Back to original message]
|