[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nyphp-talk
Subject:    Re: [nyphp-talk] array in object
From:       "Rick Retzko" <rick () click-rick ! net>
Date:       2009-01-22 2:03:47
Message-ID: 5FD5CF15E3CA49ABA220F078AF795AB2 () adam
[Download RAW message or body]

Kenneth - THANKS!  I need to go back over my code, but the curly-brackets
solved the problem:

$b=$cur->{$key}['descr']; resolves to the 10-digit phone number I was
looking for.

Best Regards - 
 
Rick
============

rick@click-rick.net
201.755.4083

-----Original Message-----
From: talk-bounces@lists.nyphp.org [mailto:talk-bounces@lists.nyphp.org] On
Behalf Of Kenneth Dombrowski
Sent: Wednesday, January 21, 2009 8:46 PM
To: NYPHP Talk
Subject: Re: [nyphp-talk] array in object


kenneth@gilgamesh:~$ php -a
Interactive mode enabled

<?php
class C {  
        public function __construct() {
                $this->phone1 = array("descr" => "Home Phone");
        }
}
$c = new C();
print $c->phone1["descr"] . "\n";
Home Phone
$key = "phone1";
print $c->{$key}["descr"] . "\n";
Home Phone
print $c->$key["descr"] . "\n";

# looking for a property named $key["descr"]


On 09-01-21 20:24 -0500, Rick Retzko wrote:
> Hi Folks -
>  
> This should be simple, but I haven't been able to debug it on my own, 
> so I'm asking for help.
>  
> I'm walking through a user's webform submission that I've put into an 
> object and comparing each of that object's properties with the current 
> properties
> ($cur) stored on mySQL database.
> The example below is input for a phone number (phone1).
>  
> This example stores the 10-digit phone number into variable $c:
> $c=$cur->phone1['descr'];
>  
> If I use $key to capture the property to be checked ('phone1'), the 
> following stores null:
> $b=$cur->$key['descr'];
>  
> Any help on understanding why $cur->$key['descr'] is not synonymous 
> with $cur->phone1['descr'] when $key='phone1' would be a help!
>  
> Best Regards -
>  
> Rick
> ============
> rick@click-rick.net
> 201.755.4083
>  

> _______________________________________________
> New York PHP User Group Community Talk Mailing List 
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> http://www.nyphp.org/show_participation.php
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php

_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic