|
Posted by Shelly on 08/06/06 18:58
"s a n j a y" <sanjay.debian@gmail.com> wrote in message
news:NaCdnUAhAvWsg0vZnZ2dnUVZ_qydnZ2d@comcast.com...
> 7h@ch wrote:
>> Sorry if I sounds like a noob (because I am one, here). I ran across
>> this earlier, and it kept bugging me. I guess someone here know a good
>> answer.
>>
>> To summerize, I was using array within a class. After some
>> manipulation, the value of the array's element that I needed wasn't
>> "echoed" right.
>>
>> For instance,
>>
>> class FootballClub
>> {
>> public $name;
>> public $stadium = "junkyard";
>> public $roster = array("gk"=>"clown", "st"=>"fool");
>> public $coach;
>> }
>>
>> $myclub = new FootballClub();
>> $myclub->name = "Liverpool";
>>
>> if ($myclub->name == "Liverpool")
>> {
>> $myclub->stadium = "Anfield";
>> $myclub->coach = "Rafa Benitez";
>> $myclub->roster["gk"] = "Pepe Reina";
>> $myclub->roster["st"] = "Robbie Fowler";
>> }
>>
>>
>> $myplayer = $myclub->roster[gk];
>> echo "your team plays at: $myclub->stadium<br>";
>> echo "your goal keeper is: $myclub->roster[gk]<br>");
>>
>> ---------
>> Problem:
>>
>> As is, the 2nd line output is: "your goal keeper is: Array[gk]" thought
>> $myplayer gets the right value.
>>
>> Any plausible explaination, please?
>>
>> Thanks.
>>
>
> Although not strictly necessary in php, always put your variables outside
> of quotes. This came to me easily as I was developing in c and C++ before
> I moved on to PHP.
Hmm. I looke at someone else's answer of putting braces in. I thought to
myself, "Great, I just learned something by reading this newgroup. Store it
away". When I saw your response I thought to myself "Why hadn't I come
across this problem before, myself?". Well, your answer showed me why. I
would have written it as:
echo "your goal keeper is:" . $myclub->roster['gk'] . "<br>";
and never have had that difficulty. My background in C and java developed
that same habit in me.
Shelly
[Back to original message]
|