Page 1 of 1
[SOLVED] help with arrays
Posted: Thu Mar 10, 2011 12:03 am
by stevestark5000
in the below code, both the echo statements gives the error. Parse error: syntax error, unexpected '['.
How to write the code using val not $val without giving the error so that val['archive_days'] would work?
Code: Select all
<?php
val['archive_days'] = 9;
echo $val['archive_days'];
echo val['archive_days'];
?>
Re: help with arrays
Posted: Thu Mar 10, 2011 12:12 am
by tnrh1
I dont really understand what are you trying to do, but this is the way to work with arrays:
http://php.net/manual/en/language.types.array.php
And you cant print an Array, you need to print the Placeholders by a loop.
Re: help with arrays
Posted: Thu Mar 10, 2011 12:33 am
by stevestark5000
I am still trying to understand this line of code. Why val is used instead of $val. also what is -> in the code. note the code works great. I am just trying to understand it fully.
Code: Select all
if($_SESSION['SES_ART_master']->val['archive_days']>0)
Re: help with arrays
Posted: Thu Mar 10, 2011 11:00 am
by AbraCadaver
stevestark5000 wrote:I am still trying to understand this line of code. Why val is used instead of $val. also what is -> in the code. note the code works great. I am just trying to understand it fully.
Code: Select all
if($_SESSION['SES_ART_master']->val['archive_days']>0)
$_SESSION is an array and
['SES_ART_master'] is an element of that array that contains an object with a property called
val which is an array that has an element called
['archive_days']. The -> is how you access properties and methods of an object:
Code: Select all
$object->property = 'something';
$something = $object->someFunction();
Re: help with arrays
Posted: Thu Mar 10, 2011 7:45 pm
by stevestark5000
what i was also asking for is how to output val instead of $val and without an error. I found a solution.
echo $_SESSION['SES_ART_master']->val['archive_days']
this topic is solved. thank you.