Re: [PHP] a basic array question!

2005-06-30 Thread Richard Lynch
On Sat, June 25, 2005 2:01 pm, bruce said:
 feel kind of foolish posting this.. but i can't seem to figure it out for
 now..

Here's a way to tackle this kind of thing in the future:

Divide and Conquer.

print_r($foo) prints out a BUNCH of stuff.

Focus only on the outer layer:

 i have an array, i can do a print_r($foo) and get the following:
 Array
 (
 [bookmark] = 1
 [facets] = Array
.
.
.


Then simply do:

print_r($foo['facets']);

Now you can ignore a bunch of crap you don't care about.

Focus on the outer layer and begin again:

Array
(
[0] = Array
(
[lastname] = form id=facet-lastname
input type=hidden name=list value= /
input type=hidden name=offset value=0 /
input type=hidden name=orderBy value=username /
input type=hidden name=sort value=asc /
strongName:/strong
input type=text name=_lastname value= style=width: 125px /
input type=submit value=Search /
/form
}

Okay, now we have:

print_r($foo['facets'][0]);


Array
(
[lastname] = form id=facet-lastname
input type=hidden name=list value= /
input type=hidden name=offset value=0 /
input type=hidden name=orderBy value=username /
input type=hidden name=sort value=asc /
strongName:/strong
input type=text name=_lastname value= style=width: 125px /
input type=submit value=Search /
/form
}

Finally, print_r($foo['facets'][0]['lastname'] is your answer.

It won't always be [] -- If you are using objects you might need - in
there somewhere.

Figuring out where gets a lot easier if you focus on the Big Picture --
only the outer layer of your data structure, and drill down.

If at some point you know you need *ALL* the elements of an array, that's
easy enough.

That's the point at which you put in a loop to walk through them.

BUT

During your development, write the loop, see that it dumps out all the
elements, or at least a whole lot of stuff, and then stick an exit; at
the end, and focus on JUST the first element to tear that apart.

You can take the exit; out when you are all done, and it will work for all
the elements, assuming your data is well-formed.

In the meantime, focus on the outer layer, and focus on just ONE element
at a time, to avoid confusing yourself.

I do this all the time, especially when I'm dealing with somebody else's
structured data, and I don't really know what they've done.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] a basic array question!

2005-06-25 Thread Robbert van Andel
If you want to get the lastname value of the array you supplied you would do
this

$value = $foo['facets'][0]['lastname'];

This would give you the HTML form that you have stored in your array.

Robbert

-Original Message-
From: bruce [mailto:[EMAIL PROTECTED] 
Sent: Saturday, June 25, 2005 2:02 PM
To: php-general@lists.php.net
Subject: [PHP] a basic array question!

feel kind of foolish posting this.. but i can't seem to figure it out for
now..

i have an array, i can do a print_r($foo) and get the following:
Array
(
[bookmark] = 1
[facets] = Array
(
[0] = Array
(
[lastname] = form id=facet-lastname
input type=hidden name=list value= /
input type=hidden name=offset value=0 /
input type=hidden name=orderBy value=username /
input type=hidden name=sort value=asc /
strongName:/strong
input type=text name=_lastname value= style=width: 125px /
input type=submit value=Search /
/form
}

i simply need to know how to get the actual value of an element ('lastname')
to do:
$cat = $foo-facets[0]-['lastname'] (obviously, this doesn't work!!)

i've tried a variety of possible choices, with no luck...

any ideas/thoughts/etc...

thanks

bruce
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] a basic array question!

2005-06-25 Thread Brian V Bonini
On Sat, 2005-06-25 at 17:01, bruce wrote:
 feel kind of foolish posting this.. but i can't seem to figure it out for
 now..
 
 i have an array, i can do a print_r($foo) and get the following:
 Array
 (
 [bookmark] = 1
 [facets] = Array
 (
 [0] = Array
 (
 [lastname] = form id=facet-lastname
 input type=hidden name=list value= /
 input type=hidden name=offset value=0 /
 input type=hidden name=orderBy value=username /
 input type=hidden name=sort value=asc /
 strongName:/strong
   input type=text name=_lastname value= style=width: 125px /
   input type=submit value=Search /
 /form
   }
 
 i simply need to know how to get the actual value of an element ('lastname')
 to do:
 $cat = $foo-facets[0]-['lastname'] (obviously, this doesn't work!!)
 

$lastname = $foo['facets'][0]['lastname'];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php