[SOLVED] help with arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

[SOLVED] help with arrays

Post 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'];
?>
Last edited by stevestark5000 on Thu Mar 10, 2011 7:46 pm, edited 1 time in total.
tnrh1
Forum Newbie
Posts: 14
Joined: Tue Nov 30, 2010 8:27 am

Re: help with arrays

Post 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.
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: help with arrays

Post 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)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: help with arrays

Post 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();
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: help with arrays

Post 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.
Post Reply