Jump to content

help with Multidimensional arrays


spires

Recommended Posts

Hi.

 

I'm guessing this should be easy, but having never used them i'm stuck.

 

I have an array and count that i'm trying to place inside of a Multidimensional array.

 

$value = count from 1-infinite

$keywords = an Array contain X amount of stings.

 

What I want to do, (on submit) is join the two together in to one array.

So the lists of "$keywords" can be referenced by a $value.

 

E.G:

value1 => keyword1

value1 => keyword2

value1 => keyword3

 

value2 => keyword1

value2 => keyword2

value2 => keyword3

 

etc

 

So, I'm thinking something like this, but i'm purely guessing here:

 

$value = 1;
$keywords = array("key1", "key2", "key3");

$arr = array($value => array($keywords));

//then loop through

foreach($arr as $val){
     foreach($val as $keywords){
             echo $val. " - " .$keywords."\n";
     }
}


//output
1 - key1
1 - key2
1 - key3

 

 

Any ideas where I'm going wrong, or how this should look?

 

Thanks :)

Link to comment
Share on other sites

ok thanks. But can't get that to work.

 

 

I'm now trying:

        $adgroup = $_POST['adgroup'];     // This is an array, 100's of keywords
$arrValues = array();

for($v=0;$v<$value;$v++){
	$arrValues[] = $v;
	foreach($adgroup as $adgroups){
		$cleanGroup = trim($adgroups);
		$arrValues[$v] = $cleanGroup;
	}
}
	print_r($arrValues);

 

This works great.

But, I can't keep adding to the array.

 

E.G:

$v = 1

$arrValues[$v] = $cleanGroup;

 

So, what I want is:

$arrValues[1]['key1'];

$arrValues[1]['key2'];

$arrValues[1]['key3'];

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.