annihilate Posted January 16, 2009 Share Posted January 16, 2009 Hi there, I have just switched over to php5 and so have started making the variables in my classes private and then greating a public function which gets them. Previously, I had this code in a page: echo $movies_base->cert_array[$movie['cert']]; cert_array is a var in the movies base class, and it is an array. Under php5, I have made cert_array private, and added a getter for it. So now I have echo $movies_base->get_cert_array()[$movie['cert']]; The above line is not valid code. My question is: is it possible to do what I need in one line or do I have to something like the following: $cert_array = $movies_base->get_cert_array(); echo $cert_array[$movie['cert']]; Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/141143-help-with-syntax-for-looking-in-an-array/ Share on other sites More sharing options...
RussellReal Posted January 16, 2009 Share Posted January 16, 2009 in the cert array function you could do function get_cert_array($index = null) { if ($index) { return $theArray[$index]; } else { return $theArray; } } thaut will make the arguement optional and then do something like echo $movies_base->get_cert_array('cert'); Quote Link to comment https://forums.phpfreaks.com/topic/141143-help-with-syntax-for-looking-in-an-array/#findComment-738761 Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 in the cert array function you could do function get_cert_array($index = null) { if ($index) { return $theArray[$index]; } else { return $theArray; } } thaut will make the arguement optional and then do something like echo $movies_base->get_cert_array('cert'); The [ code] and [ /code] tags are your friends, not enemy's. Quote Link to comment https://forums.phpfreaks.com/topic/141143-help-with-syntax-for-looking-in-an-array/#findComment-738764 Share on other sites More sharing options...
RussellReal Posted January 16, 2009 Share Posted January 16, 2009 tru dat but like.. I don't have to read over my own code, so that rule should probably only apply to the ppl asking.. but if it bothers you I'll take some initiative hey btw Quote Link to comment https://forums.phpfreaks.com/topic/141143-help-with-syntax-for-looking-in-an-array/#findComment-738766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.