Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Array question....

Status
Not open for further replies.

pgferro

Programmer
Aug 21, 2001
111
0
0
BS
Hi,

How can I populate an array so that i could use it this way :

Code:
echo $client->name
echo $client->phone

etc etc ??

The array will be populated manually.

Thanks !!

--
PG
 
$client = array ('name' => 'some value', 'phone' => 'some other value');


or


$client = array();
$client['name'] = 'some value';
$client['phone'] = 'some other value';


There's likely other ways to do it. All this is describe here:
Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hey Tanstaafl,

tried both method and i do not get anything outputted when : echo $client->name;

Any idea ?

--
PG
 
I understand that, but my question was : how do i populate an array (or object) to use "echo $client->name;" format.
That means that i prefer to use that structure for reasons too long to explain....

Wanna give the best answer ? Check the question !

:)

--
PG

 
Okay, I'm confused.

Should I ignore the fact that you use the "->" object-deference operator, pay attention only to your text and the subject line of this thread and talk about arrays?

Or should I ignore all your text and the subject line of this thread, pay attention only to your use of the "->" object dereference operator and start talking about objects?

I really need to know, as the two things are different beasts and are not interchangeable.

If it's the former, you have my answer. If we're talking arrays, you're trying to use the wrong operator.

If the latter, insufficient data for a meaningful answer. What does the underlying object look like? What version of PHP are you running? Is the object variable private or protected? Was there a class method provided for assigning values to that variable?

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Well,
I thought my question was pretty straightforward, but evidently it was not.
I was looking for a way to store data in php and be able to display with $whatever->whatever format. I thought (wrongly) this was probably in relation to some array manipulation, hence the subject line. I also thought (wrongly again) that some of the gurus here in tek-tips would have identified my needs even with a non correct subject line and, using a bit of flexibility, understood what my question was really about.

Fortunately I found out a way to do it myself, so my problem is now solved.

Thanks anyway, I know you dedicate a lot of your time for this board and that's something that is really appreciated.

--
PG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top