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.. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 14, 2013 Share Posted January 14, 2013 (edited) 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"]}"; } Edited January 14, 2013 by requinix Quote Link to comment 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.. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
jkkenzie Posted January 14, 2013 Author Share Posted January 14, 2013 (edited) yes i did: foreach ($this->chItems2[$Lnkkey] as $Res => $ChkLynks) { echo $ChkLynks["text"] ."-".$ChkLynks["url"]; } Print_r($this->chItems2[$Lnkkey]) produces the array above. Edited January 14, 2013 by jkkenzie Quote Link to comment Share on other sites More sharing options...
Barand Posted January 14, 2013 Share Posted January 14, 2013 (edited) 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"]}"; } } Edited January 14, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
jkkenzie Posted January 15, 2013 Author Share Posted January 15, 2013 Now things are working. Thanks! alot Quote Link to comment 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.