jkkenzie Posted January 14, 2013 Share Posted January 14, 2013 Hi! am trying a shortcut here: Array ([981_P] => Array([text] => why Kilele[url] => /www/kilele/pages/why_Kilele.htm) [982_P] => Array([text] => About Kenya[url] => /www/kilele/pages/About_Kenya.htm) [983_P] => Array([text] => Unique value proposition[url] => /www/kilele/pages/Unique_value_proposition.htm) [984_P] => Array([text] => About Tanzania[url] => /www/kilele/pages/About_Tanzania.htm) [985_P] => Array([text] => About Uganda[url] => /www/kilele/pages/About_Uganda.htm) ) i want to use all [text] and , without using the outer array with indexes 982_p e.t.c .? Can i merge them leaving out the first array index with 982_p, 983_p e.t.c? thanks in advace.. Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/ Share on other sites More sharing options...
requinix Posted January 14, 2013 Share Posted January 14, 2013 The only way you could merge them into one single-dimension array would be if the texts or urls were unique, in which case you make one be the array key and the other be the value. What's wrong with a multidimensional array? It's not like they're hard to use or anything, just need another set of []s or a second loop. Actually in your case there's no need for a second loop because the inner array is a collection of individual pieces of data. foreach ($array as $id => $data) { echo "text={$data["text"]} url={$data["url"]}"; } Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405655 Share on other sites More sharing options...
jkkenzie Posted January 14, 2013 Author Share Posted January 14, 2013 yes i tried that, but you have to go through the Array like foreach ($this->chItems[$Lnkkey] as $Res => $ChkLynks) { echo $ChkLynks["982_P"]["text"] ."-".$ChkLynks["983_P"]["url"]; } You have to add the ["983_P"].... That is what am trying to avoid.. Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405659 Share on other sites More sharing options...
Barand Posted January 14, 2013 Share Posted January 14, 2013 yet not a ["983_P"]. to be seen in the code requinix posted Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405662 Share on other sites More sharing options...
jkkenzie Posted January 14, 2013 Author Share Posted January 14, 2013 YES like requinix posted, though it does not work. Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405665 Share on other sites More sharing options...
Jessica Posted January 14, 2013 Share Posted January 14, 2013 Did you change $array to your actual array? Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405667 Share on other sites More sharing options...
jkkenzie Posted January 14, 2013 Author Share Posted January 14, 2013 yes i did: foreach ($this->chItems2[$Lnkkey] as $Res => $ChkLynks) { echo $ChkLynks["text"] ."-".$ChkLynks["url"]; } Print_r($this->chItems2[$Lnkkey]) produces the array above. Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405669 Share on other sites More sharing options...
Barand Posted January 14, 2013 Share Posted January 14, 2013 then it sounds like you need to combine the code foreach ($this->chItems2[$Lnkkey] as $Res => $ChkLynks) { foreach ($ChkLynks as $data) { echo "text={$data["text"]} url={$data["url"]}"; } } Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405711 Share on other sites More sharing options...
jkkenzie Posted January 15, 2013 Author Share Posted January 15, 2013 Now things are working. Thanks! alot Link to comment https://forums.phpfreaks.com/topic/273157-use-an-array-inside-another-array/#findComment-1405764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.