CodeIgniter Forums
Arrays - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Arrays (/showthread.php?tid=37032)



Arrays - El Forum - 12-24-2010

[eluser]Milos[/eluser]
Hi, all.

I am doing video tutorials, and I can't find any info about strange uses of arrays here.

I can give you an example:

// this is the code from controller:

$data['name'] = "Milos";

// i transfer the $data to the view

$this->load->view('home', $data);

// this is the code from the view

<?php echo $name; ?>

So this is the thing that I do not understand.
We have an array $data and 'name' is just a string index for that array.
How can I access it like $name - normally it should be $data('name');
I didn't find any example like it in PHP manual so I don't know what is this.
Thanks,

Milos


Arrays - El Forum - 12-24-2010

[eluser]WanWizard[/eluser]
Behold the magic of the extract function: http://php.net/manual/en/function.extract.php


Arrays - El Forum - 12-24-2010

[eluser]Milos[/eluser]
[quote author="WanWizard" date="1293220365"]Behold the magic of the extract function: http://php.net/manual/en/function.extract.php[/quote]

Thanks for answering.

So you want to say that this function is implemented here already, when passing values from controller to the view?


Arrays - El Forum - 12-24-2010

[eluser]WanWizard[/eluser]
Yes, in the _ci_load() method of the Loader library, used when you call $this->load->view().


Arrays - El Forum - 12-24-2010

[eluser]Milos[/eluser]
[quote author="WanWizard" date="1293223738"]Yes, in the _ci_load() method of the Loader library, used when you call $this->load->view().[/quote]
Thank you!