Forum Moderators: coopster

Message Too Old, No Replies

setting array to a field failed

         

orion_rus

9:25 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



Hello world i have following problem:
i have

$METAR['cityname']='paris';
$METAR['cityid']=12;

then in a constructor i call

$this->setValue('metar',$METAR);

function setValue($field, $value){
$this->values[$field] = $value;
}

i got $this->value['metar']='Array';

it's not an array it's just a word and i can't make it save via real array
Anybody can help me?

[edited by: ergophobe at 11:18 pm (utc) on Feb. 19, 2005]
[edit reason] formatted for readability [/edit]

ergophobe

11:17 pm on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$METAR is an array. So everything is right

orion_rus

10:05 am on Feb 20, 2005 (gmt 0)

10+ Year Member



but how i can save the array with such method, i need to get it in the other side of site) but it's a word 'Array' which not help me)

hakre

6:20 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i got $this->value['metar']='Array';

as ergophobe wrote, this is all correct (you made no mistake). as you wrote: this don't helps you at all. but i tell you, yes, this is very important for you.

while

echo($this->value['metar']);
will print out
Array
php only shows you, that the data can't be written out as a string. if you want to look into that array, use
print_r($this->value['metar']);
which will print out any content of any variable and even the structure. then you maybe even see yourself, that using
echo($this->value['metar']['cityname']);
will print out
paris
.

so really everything is in the right order and you can acces any value in the array, you just have to name the arraykey!

orion_rus

7:25 pm on Feb 20, 2005 (gmt 0)

10+ Year Member



i make foreach to it and it does error saying what it's not an array( may be it's my mistake i try it again but still i can't access to a value like ->value['metar']['cityname'] ((
Thanks for helping me