CodeIgniter Forums
Getting associative array value without foreach loop? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Getting associative array value without foreach loop? (/showthread.php?tid=48529)



Getting associative array value without foreach loop? - El Forum - 01-19-2012

[eluser]jsuissa[/eluser]
Hi,

So I'm able to get name/values with a foreach loop from $data['resume'] shown below.

However I can't figure out how to access a single value from this row_array provided I already know the name associated with the value (i.e. name: vanity_name value: ABC)

Is it possible to get this value without using a foreach loop?

Code:
$data['resume'] = $this->resume_model->get_resume_profile($id);

Thanks in advance for any help!

Justin


Getting associative array value without foreach loop? - El Forum - 01-19-2012

[eluser]InsiteFX[/eluser]
Try
Code:
echo $data['resume']['vanity_name'];



Getting associative array value without foreach loop? - El Forum - 01-19-2012

[eluser]Dhanapal MCA[/eluser]
Hi you can use this below code:

echo $data['resume']['vanity_name'];


Getting associative array value without foreach loop? - El Forum - 01-20-2012

[eluser]Bhashkar Yadav[/eluser]
extract() function may help you. it imports variables into the local symbol table from an array.


Getting associative array value without foreach loop? - El Forum - 01-20-2012

[eluser]jsuissa[/eluser]
Thanks so much, echo $data[‘resume’][‘vanity_name’]; worked perfectly.

I will also check out the extract function.

Best,

Justin


Getting associative array value without foreach loop? - El Forum - 01-20-2012

[eluser]InsiteFX[/eluser]
You can also assign it to a new string variable.
Code:
$vanity = $data['resume']['vanity_name'];