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!
Is this the normal case, accessing only one element of the entire array?
Then why not add a method to the class that only returns one element? (possible answer: "I'm only using the class" )
It's not that I am looking for another way to do this but that I want to find a short cut because it's one of those things I have always wondered about.
If you are outputting within html you really only want to output variables rather than do logic and it is annoying having to create variables to query later.
It's not a big issue, just like to find shortcuts like
Short-tags will be removed from future versions of PHP - they 'fail' markup standards and finally PHP are pulling their socks up about this.
So your code with shortags will die of death when you try to run it, and in the likely scenario of that happening - all your code will be visible to the end user... != good.
add a method your your class, as posted above.. it's not hard:
public function getArrayValue($ind)
{
if (isset($this->array[$ind]))
{
return $this->array[$ind];
}
else
{
throw new IndexOutOfBoundsException ('Index ' . (int)$ind . ' out of bounds');
}
}