vincej Posted July 23, 2011 Share Posted July 23, 2011 Hi - I'm following a course on CodeIgniter where the tutorial uses some syntax to describe an array inside and object. I have never seen this syntax before for creating an array - specifically the way they splice together the $data variable with the name of the array ['title'] . It's easy enough to follow however, I was wondering why anyone would use it, if it was standard adn if it had any special relevance. Thanks ! class Blog extends Controller{ function index() { $data['title'] = "My Bog Title"; $data['heading'] = "My Bog Heading" $this->load->view('blog_view', $data) } } Quote Link to comment https://forums.phpfreaks.com/topic/242670-need-explanation-of-data-array-inside-an-object/ Share on other sites More sharing options...
dcro2 Posted July 23, 2011 Share Posted July 23, 2011 Arrays can have numeric and alphanumerical keys, so they can be [1], [2], ['08'] or ['alphabet']. Arrays can be simply declared by setting one of its indices. It can be nicer to look at than say, $data = array('title' => "My Bog Title", 'heading' => "My Bog Heading");. Am I missing something about your question? http://www.php.net/manual/en/language.types.array.php PS: Bog? Quote Link to comment https://forums.phpfreaks.com/topic/242670-need-explanation-of-data-array-inside-an-object/#findComment-1246408 Share on other sites More sharing options...
xyph Posted July 23, 2011 Share Posted July 23, 2011 Also, $arr['key'] = 'anything'; will work as well. Quote Link to comment https://forums.phpfreaks.com/topic/242670-need-explanation-of-data-array-inside-an-object/#findComment-1246411 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.