Jump to content

Use an array inside another array


jkkenzie

Recommended Posts

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

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"]}";
}

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.