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

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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